problem:
if I fix:
I want to see AppCompatTextView with Android-Studio.
How to see the AppCompatTextView?
Nothing Error! I don't know why..
Please help this problem..
activity_searchresult.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/cfb"
tools:context=".ResultActivity">
<FrameLayout
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="600dp"
android:background="@color/cfb"
tools:context=".ResultActivity">
<TextView
android:id="@+id/resultText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/result_text1"
android:textColor="@color/black"
android:textSize="23sp"
android:layout_marginLeft="30dp"
app:layout_constraintBottom_toTopOf="@+id/resultText2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/resultText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/result_text2"
android:textColor="@color/black"
android:textSize="23sp"
android:layout_marginBottom="30dp"
app:layout_constraintBottom_toTopOf="@+id/resultViewPager2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageButton
android:id="@+id/resultFilterButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="15dp"
android:layout_marginRight="28dp"
android:background="@color/cfb"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/dots_indicator"
app:srcCompat="@drawable/filter" />
<TextView
android:id="@+id/filterText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="25dp"
android:layout_marginRight="40dp"
android:text="@string/filter"
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/resultFilterButton" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/resultViewPager2"
android:layout_width="270dp"
android:layout_height="270dp"
android:layout_marginBottom="190dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_bias="0.3" />
<com.tbuonomo.viewpagerdotsindicator.DotsIndicator
android:id="@+id/dots_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="110dp"
app:dotsColor="@color/white"
app:dotsCornerRadius="8dp"
app:dotsSize="14dp"
app:dotsSpacing="4dp"
app:dotsWidthFactor="2.5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/resultViewPager2"
app:layout_constraintBottom_toBottomOf="parent"
app:progressMode="true"
app:selectedDotColor="@color/black" />
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="30dp"
app:layout_constraintBottom_toTopOf="@+id/resultViewPager2"
app:srcCompat="@drawable/cafebot" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ResultActivity">
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/navigationView"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:itemTextColor="@drawable/bottom_icon_color"
app:itemIconTint="@drawable/bottom_icon_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="parent"
app:menu="@menu/bottom_nav" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
</LinearLayout>
result_item_viewpager.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/result_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/result_menu_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="@android:color/black"
android:textSize="26sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/result_sample_image" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/result_cafe_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="@android:color/black"
android:textStyle="bold"
android:textSize="23sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/result_menu_name" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/result_product_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textColor="@android:color/black"
android:textSize="22sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/result_cafe_name" />
<ImageView
android:id="@+id/result_sample_image"
android:layout_width="270dp"
android:layout_height="270dp"
android:layout_marginTop="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>
ResultDataPage.java:
package com.example.myapplication;
public class ResultDataPage {
int resultImage;
String resultCafeName;
String resultMenuName;
int resultPrice;
public ResultDataPage(int image, String menuName, String cafeName, int price){
this.resultImage = image;
this.resultMenuName = menuName;
this.resultCafeName = cafeName;
this.resultPrice = price;
}
public int getImage(){
return resultImage;
}
public void setImage(int image) {
this.resultImage = image;
}
public String getMenuName(){
return resultMenuName;
}
public void setMenuName(String menuName) {
this.resultMenuName = menuName;
}
public String getCafeName() {
return resultCafeName;
}
public void setCafeName(String cafeName) {
this.resultCafeName = cafeName;
}
public int getPrice(){
return resultPrice;
}
public void setPrice(int price){
this.resultPrice = price;
}
}
ResultViewPagerAdapter.java:
package com.example.myapplication;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
public class ResultViewPagerAdapter extends RecyclerView.Adapter<ResultViewHolderPage> {
private ArrayList<ResultDataPage> listData;
ResultViewPagerAdapter(ArrayList<ResultDataPage> data) {
this.listData = data;
}
@Override
public ResultViewHolderPage onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
View view = LayoutInflater.from(context).inflate(R.layout.result_item_viewpager, parent, false);
return new ResultViewHolderPage(view);
}
@Override
public void onBindViewHolder(ResultViewHolderPage holder, int position) {
if(holder instanceof ResultViewHolderPage){
ResultViewHolderPage viewHolder = (ResultViewHolderPage) holder;
viewHolder.onBind(listData.get(position));
}
}
@Override
public int getItemCount() {
return listData.size();
}
}
ResultViewHolderPage.java:
package com.example.myapplication;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;
public class ResultViewHolderPage extends RecyclerView.ViewHolder {
private ImageView resultImage;
private TextView resultCafeName;
private TextView resultMenuName;
private TextView resultPrice;
ResultDataPage resultData;
ResultViewHolderPage(View itemView) {
super(itemView);
resultCafeName = itemView.findViewById(R.id.result_cafe_name);
resultImage = itemView.findViewById(R.id.result_sample_image);
resultPrice = itemView.findViewById(R.id.result_product_price);
resultMenuName = itemView.findViewById(R.id.result_menu_name);
}
public void onBind(ResultDataPage resultData){
this.resultData = resultData;
resultMenuName.setText(resultData.getMenuName());
resultCafeName.setText(resultData.getCafeName());
resultImage.setImageResource(resultData.getImage());
resultPrice.setText(Integer.toString(resultData.getPrice()).concat("원"));
}
}
ResultActivity.java:
package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.tbuonomo.viewpagerdotsindicator.DotsIndicator;
import java.util.ArrayList;
public class ResultActivity extends AppCompatActivity {
// 가운데
private ViewPager2 result_ViewPager2;
private DotsIndicator dotsIndicator;
private ArrayList<ResultDataPage> list;
// 바텀네비게이션뷰
private BottomNavigationView bottomNav;
private FragmentManager fragmentManager = getSupportFragmentManager();
private SearchPage fragmentSearch = new SearchPage();
private HomePage fragmentHome = new HomePage();
private CafePage fragmentCafe = new CafePage();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_searchresult);
this.viewpage(); // 뷰페이저 (메뉴검색결과값)
// 바텀네비게이션
bottomNav = findViewById(R.id.navigationView);
bottomNav.setOnNavigationItemSelectedListener(new ResultActivity.ItemSelectedListener());
}
private void viewpage(){
list = new ArrayList<>();
list.add(new ResultDataPage(R.drawable.sample_1, "아메리카노","스타벅스", 4900));
list.add(new ResultDataPage(R.drawable.sample_2, "아메리카노","투썸플레이스", 4100));
list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","이디야커피", 3000));
list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));
list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));
list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));
list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));
list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));
list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));
list.add(new ResultDataPage(R.drawable.sample_3, "아메리카노","EDIYA", 3000));
result_ViewPager2 = findViewById(R.id.resultViewPager2);
result_ViewPager2.setAdapter(new ResultViewPagerAdapter(list));
dotsIndicator = findViewById(R.id.dots_indicator);
dotsIndicator.setViewPager2(result_ViewPager2);
}
//바텀네비
class ItemSelectedListener implements BottomNavigationView.OnNavigationItemSelectedListener {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
switch (menuItem.getItemId()) {
case R.id.searchItem:
Intent intent1 = new Intent(getApplicationContext(), com.example.myapplication.SearchActivity.class);
startActivity(intent1);
//transaction.replace(R.id.frameLayout, fragmentSearch).commitAllowingStateLoss();
break;
case R.id.homeItem:
Intent intent2 = new Intent(getApplicationContext(), com.example.myapplication.MainActivity.class);
startActivity(intent2);
//transaction.replace(R.id.frameLayout, fragmentHome).commitAllowingStateLoss();
break;
case R.id.cafeItem:
Intent intent3 = new Intent(getApplicationContext(), com.example.myapplication.MainCflistActivity.class);
startActivity(intent3);
//transaction.replace(R.id.frameLayout, fragmentCafe).commitAllowingStateLoss();
break;
}
return true;
}
}
}
UPDATE: (Comments below for details) At the end, text was hidden because the ViewPager was too small.
The AppCompatTextView is a retro-compatible text view for old Support Library support. Which is your minimum supported SDK version? You don't need this if you are using AndroidX.
However, it comes with this dependecy you have to put in your module build.gradle file:
implementation 'com.android.support:appcompat-v7:28.0.0'
After this, sync Gradle and you can use the "AppCompatTextView":
References: https://developer.android.com/topic/libraries/support-library/packages#v7 https://developer.android.com/topic/libraries/support-library/setup#choosing https://developer.android.com/reference/androidx/appcompat/widget/AppCompatTextView