GridView issue with large data while scrolling - android

I am having problem with "GridView".If I use 6 items then it is not creating problem while scrolling but as I increase no. of items its behavior is unpredictable.
Please check the following video link for better understanding my problem:
GridView Issues video link
I am attaching my codes here:
activity_achievements.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:background="#color/green_color">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/back_iv"
android:text="Acheivements"
android:textColor="#color/white_color"
android:textSize="24sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/back_iv"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/back" />
<TextView
android:id="#+id/total_achievements_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:text="0/15"
android:textColor="#color/white_color"
android:textSize="24sp"
android:textStyle="bold" />
</RelativeLayout>
<GridView
android:id="#+id/acheivements_gv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/header"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp" />
</RelativeLayout>
achievements_row.xml
<?xml version="1.0" encoding="utf-8"?>
<com.xyz.quitsmoking.view.AchievementsView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<android.support.v7.widget.CardView
android:id="#+id/card_view2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/card_view1"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
card_view:cardCornerRadius="2dp"
android:background="#color/white_color"
card_view:contentPadding="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/image_iv"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_margin="10dp"
android:src="#drawable/achievement" />
<TextView
android:id="#+id/title_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:textSize="20sp"
android:padding="10dp"
android:text="Himalyi"
android:textColor="#color/green_color" />
<TextView
android:id="#+id/desc_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:textSize="16sp"
android:padding="10dp"
android:text="5 cigarettes non-smoked"
android:textColor="#color/teal_color" />
</LinearLayout>
</android.support.v7.widget.CardView>
</pairroxz.com.quitsmoking.view.AchievementsView>
AchievementsAdapter.java
public class AchievementsAdapter extends BaseAdapter {
private Context context;
private ArrayList<Achievements> list;
private LayoutInflater inflater;
public AchievementsAdapter(Context context,ArrayList<Achievements> list){
this.context = context;
this.list = list;
initialize();
}
private void initialize() {
inflater = LayoutInflater.from(context);
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
AchievementsView view = null;
if(view==null) {
view = (AchievementsView) inflater.inflate(R.layout.achievements_row,null);
}else{
view = (AchievementsView) convertView;
}
view.setContents(list.get(position));
notifyDataSetChanged();
return view;
}
}
AchievementsView.java
public class AchievementsView extends RelativeLayout {
private TextView title_tv,desc_tv;
private ImageView image_iv;
public AchievementsView(Context context) {
super(context);
}
public AchievementsView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AchievementsView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
#TargetApi(Build.VERSION_CODES.LOLLIPOP)
public AchievementsView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
#Override
protected void onFinishInflate() {
super.onFinishInflate();
initialize();
}
private void initialize() {
image_iv = (ImageView)findViewById(R.id.image_iv);
title_tv = (TextView)findViewById(R.id.title_tv);
desc_tv = (TextView) findViewById(R.id.desc_tv);
}
public void setContents(Achievements achievements){
image_iv.setImageDrawable(getContext().getResources().getDrawable(achievements.getImg()));
title_tv.setText(achievements.getTitle());
desc_tv.setText(achievements.getDesc());
}
}
AchievementsActivity.java
public class AchievementsActivity extends AppCompatActivity implements View.OnClickListener {
private GridView achievements_gv;
private AchievementsAdapter adapter;
private ArrayList<Achievements> list;
DatabaseHelper helper;
private ImageView back_iv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_achievements);
initialize();
}
private void initialize() {
helper = DatabaseHelper.getInstance(this);
back_iv = (ImageView) findViewById(R.id.back_iv);
achievements_gv = (GridView) findViewById(R.id.acheivements_gv);
list = new ArrayList<Achievements>();
getData();
setListener();
}
private void setListener() {
back_iv.setOnClickListener(this);
}
private void getData() {
list = helper.getAchievementsList();
//list =
adapter = new AchievementsAdapter(this, list);
achievements_gv.setAdapter(adapter);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.back_iv:
onBackPressed();
break;
}
}
}

if(view == null)
view.setTag(viewHolder);
viewHolder = (ViewHolder) view.getTag();
don't use this. or send your code

Related

android: Customized gridview is not showing in design view

using Android studio, I cannot find anything of my customized gridview in my design view.
Android Studio Arctic Fox | 2020.3.1 Patch 3
Build #AI-203.7717.56.2031.7784292, built on October 1, 2021
Runtime version: 11.0.10+0-b96-7249189 amd64
VM: OpenJDK 64-Bit Server VM by Oracle Corporation
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 8
Registry: external.system.auto.import.disabled=true, debugger.watches.in.variables=false, compiler.automake.allow.when.app.running=true, ide.balloon.shadow.size=0
First of all, one of my customized gridview which can be seen is showing below:
public class PickWaveListGridVIew extends GridView {
public PickWaveListGridVIew(Context context, AttributeSet attrs) {
super(context, attrs);
initialize();
}
private void initialize() {
List<WaveListItemDTO> dataList = requestForWaveList();
setAdapter(new PickWaveListAdapter(dataList, getContext()));
}
private List<WaveListItemDTO> requestForWaveList() {
//todo demo data
return Lists.newArrayList(new WaveListItemDTO("S202205250001", "S202205250001", "2022-05-25 10:42:01"),
new WaveListItemDTO("S202205250002", "S202205250002", "2022-05-25 10:42:02"),
new WaveListItemDTO("S202205250003", "S202205250003", "2022-05-25 10:42:03")
);
}
/**
* dto class of demo
*/
private static class WaveListItemDTO {
private String waveId;
private String waveCode;
private String createTime;
public WaveListItemDTO() {
}
public WaveListItemDTO(String waveId, String waveCode, String createTime) {
this.waveId = waveId;
this.waveCode = waveCode;
this.createTime = createTime;
}
}
private class PickWaveListAdapter extends BaseAdapter {
private final List<WaveListItemDTO> dataList;
private LayoutInflater menuInflater;
public PickWaveListAdapter(List<WaveListItemDTO> dataList, Context context) {
this.dataList = dataList;
this.menuInflater = LayoutInflater.from(context);
}
#Override
public int getCount() {
return this.dataList.size();
}
#Override
public Object getItem(int position) {
return this.dataList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
//load layout
View layout = this.menuInflater.inflate(R.layout.item_clickable_pick_wave_list_button, parent, false);
TextView waveId = layout.findViewById(R.id.item_clickable_pick_wave_list_button_wave_id);
TextView datetime = layout.findViewById(R.id.item_clickable_pick_wave_list_button_datetime);
WaveListItemDTO dto = this.dataList.get(position);
//set data to views
waveId.setText(dto.waveCode == null ? dto.waveId : dto.waveCode);
datetime.setText(dto.createTime);
return layout;
}
private <T extends BaseFunctionPageActivity> void openDetailOperationActivity(
BaseActivity currentActivity,
Class<T> clz,
String title,
String waveId) {
ActivityUtils.openNewActivity(currentActivity,
clz,
true,
null,
new JSONObjectBuilder()
.put(Constants.INTENT_PASSING_DATA_JSON_TITLE_KEY, title)
.put(Constants.INTENT_PASSING_DATA_JSON_WAVE_ID_KEY, waveId)
.build()
);
}
}
}
customized gridview R.layout.item_clickable_pick_wave_list_button
<?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"
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="#drawable/item_text_view_underline">
<!--拣货波次列表Item-->
<androidx.constraintlayout.widget.Guideline
android:id="#+id/item_clickable_pick_wave_list_button_splitter_mid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.45"
android:orientation="vertical" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/item_clickable_pick_wave_list_button_splitter_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.03"
android:orientation="vertical" />
<TextView
android:id="#+id/item_clickable_pick_wave_list_button_wave_id"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="S202205250001"
android:textSize="18sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="#+id/item_clickable_pick_wave_list_button_splitter_left"
app:layout_constraintRight_toLeftOf="#+id/item_clickable_pick_wave_list_button_splitter_mid" />
<ImageButton
android:id="#+id/item_clickable_pick_wave_list_button_img_btn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="10dp"
android:src="#drawable/right"
android:background="#color/transparent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="#+id/item_clickable_pick_wave_list_button_datetime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="2022-05-25 10:42:01"
android:textSize="18sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="#+id/item_clickable_pick_wave_list_button_splitter_mid" />
</androidx.constraintlayout.widget.ConstraintLayout>
layout 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"
android:id="#+id/activity_mws_pick_wave_list_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.originlinks.wmspda.activities.wms.pick.PickWaveListGridVIew
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="#+id/activity_mws_pick_wave_list_layout"
app:layout_constraintBottom_toBottomOf="#+id/activity_mws_pick_wave_list_layout"
android:numColumns="1"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
it is normal to see my demo data in design view like this.
So I decided to develop another customized gridview in exactly the same way, I found it failed to show in design view.
Here below is the code which has problems:
my customize gridview
public class ProductListGridView extends GridView {
private List<ProductListDTO> productList;
private List<String> itemIdList;
public ProductListGridView(Context context) {
super(context);
initialize(context);
}
public ProductListGridView(Context context, AttributeSet attrs) {
super(context, attrs);
initialize(context);
}
public ProductListGridView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize(context);
}
public ProductListGridView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initialize(context);
}
private void initialize(Context context) {
this.productList = getProductListOfSpecifiedWaveId();
this.itemIdList = this.productList.stream().map(e -> e.shelveCode + e.sku).collect(Collectors.toList());
setAdapter(new ProductItemAdapter(productList, getContext()));
}
private List<ProductListDTO> getProductListOfSpecifiedWaveId() {
//todo demo data
return Lists.newArrayList(
new ProductListDTO("F2-A01-001", "020111", "demo product name", 20, null),
new ProductListDTO("F2-A01-002", "020112", "demo product name", 20, null),
new ProductListDTO("F2-A01-003", "020113", "demo product name", 20, null),
new ProductListDTO("F2-A01-004", "020114", "demo product name", 20, null),
new ProductListDTO("F2-A01-005", "020115", "demo product nameK", 20, null)
);
}
private static class ProductListDTO {
private String shelveCode;
private String sku;
private String name;
private Integer number2Pick;
private Integer numberPicked;
private String imgUrl;
public ProductListDTO() {
}
public ProductListDTO(String shelveCode, String sku, String name, Integer number2Pick, String imgUrl) {
this.shelveCode = shelveCode;
this.sku = sku;
this.name = name;
this.number2Pick = number2Pick;
this.imgUrl = imgUrl;
this.numberPicked = 0;
}
}
private static class ProductItemAdapter extends BaseAdapter {
private final List<ProductListDTO> productList;
private final LayoutInflater menuInflater;
private final Context context;
public ProductItemAdapter(List<ProductListDTO> productList, Context context) {
this.productList = productList;
this.menuInflater = LayoutInflater.from(context);
this.context = context;
}
#Override
public int getCount() {
return this.productList.size();
}
#Override
public Object getItem(int position) {
return this.productList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
//inflate the gridview and get the needed controllers
View layout = this.menuInflater.inflate(R.layout.item_clickable_pick_product_list_button, parent, false);
TextView shelveCode = layout.findViewById(R.id.item_clickable_pick_product_list_button_shelve_code);
TextView sku = layout.findViewById(R.id.item_clickable_pick_product_list_button_sku);
TextView name = layout.findViewById(R.id.item_clickable_pick_product_list_button_name);
TextView processNum = layout.findViewById(R.id.item_clickable_pick_product_list_button_process);
ImageView img = layout.findViewById(R.id.item_clickable_pick_product_list_button_pic);
//set the controllers' value by specified dto data
ProductListDTO dto = this.productList.get(position);
shelveCode.setText(dto.shelveCode);
sku.setText(dto.sku);
name.setText(dto.name);
String initialPickNum = dto.numberPicked.toString() + "/" + dto.number2Pick.toString();
processNum.setText(initialPickNum);
//async download images from url
ImageLoader imageLoader = new ImageLoader(this.context);
imageLoader.disPlayImage(dto.imgUrl, img);
return layout;
}
}
}
customized gridview R.layout.item_clickable_pick_product_list_button
<?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"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/item_text_view_underline">
<!--拣货商品明细列表的图文按钮组件-->
<androidx.constraintlayout.widget.Guideline
android:id="#+id/item_clickable_pick_product_list_button_splitter_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_begin="10dp"
android:orientation="vertical" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/item_clickable_pick_product_list_button_splitter_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_end="10dp"
android:orientation="vertical" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/item_clickable_pick_product_list_button_splitter_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_begin="10dp"
android:orientation="horizontal" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/item_clickable_pick_product_list_button_splitter_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_end="10dp"
android:orientation="horizontal" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/item_clickable_pick_product_list_button_splitter_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintGuide_begin="150dp"
android:orientation="vertical" />
<ImageView
android:id="#+id/item_clickable_pick_product_list_button_pic"
android:layout_width="130dp"
android:layout_height="130dp"
app:layout_constraintTop_toBottomOf="#id/item_clickable_pick_product_list_button_splitter_top"
app:layout_constraintLeft_toRightOf="#id/item_clickable_pick_product_list_button_splitter_left"
app:layout_constraintBottom_toTopOf="#id/item_clickable_pick_product_list_button_splitter_bottom"
android:scaleType="centerInside"
android:src="#drawable/empty_pic"
android:background="#drawable/item_text_view_surround_border" />
<!--文本框标题-->
<TextView
android:id="#+id/item_clickable_pick_product_list_button_shelve_code_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/item_clickable_pick_product_list_button_splitter_top"
app:layout_constraintLeft_toRightOf="#id/item_clickable_pick_product_list_button_splitter_pic"
app:layout_constraintRight_toLeftOf="#id/item_clickable_pick_product_list_button_shelve_code"
android:textColor="#color/black"
android:textSize="16sp"
android:text="库位号:" />
<TextView
android:id="#+id/item_clickable_pick_product_list_button_sku_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/item_clickable_pick_product_list_button_shelve_code_title"
app:layout_constraintLeft_toRightOf="#id/item_clickable_pick_product_list_button_splitter_pic"
app:layout_constraintRight_toLeftOf="#id/item_clickable_pick_product_list_button_sku"
android:layout_marginTop="8dp"
android:textColor="#color/black"
android:textSize="16sp"
android:text="ERP-SKU:" />
<TextView
android:id="#+id/item_clickable_pick_product_list_button_name_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/item_clickable_pick_product_list_button_sku_title"
app:layout_constraintLeft_toRightOf="#id/item_clickable_pick_product_list_button_splitter_pic"
app:layout_constraintRight_toLeftOf="#id/item_clickable_pick_product_list_button_name"
android:layout_marginTop="8dp"
android:textColor="#color/black"
android:textSize="16sp"
android:lines="2"
android:ellipsize="end"
android:text="名称:" />
<TextView
android:id="#+id/item_clickable_pick_product_list_button_process_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/item_clickable_pick_product_list_button_name_title"
app:layout_constraintLeft_toRightOf="#id/item_clickable_pick_product_list_button_splitter_pic"
app:layout_constraintRight_toLeftOf="#id/item_clickable_pick_product_list_button_process"
android:layout_marginTop="8dp"
android:textColor="#color/red"
android:textSize="16sp"
android:text="应拣/已拣:" />
<!--具体内容-->
<TextView
android:id="#+id/item_clickable_pick_product_list_button_shelve_code"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/item_clickable_pick_product_list_button_splitter_top"
app:layout_constraintLeft_toRightOf="#id/item_clickable_pick_product_list_button_shelve_code_title"
app:layout_constraintRight_toLeftOf="#id/item_clickable_pick_product_list_button_splitter_right"
android:textColor="#color/black"
android:textSize="16sp"
android:text="F2-A01-001" />
<TextView
android:id="#+id/item_clickable_pick_product_list_button_sku"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/item_clickable_pick_product_list_button_shelve_code_title"
app:layout_constraintLeft_toRightOf="#id/item_clickable_pick_product_list_button_sku_title"
app:layout_constraintRight_toLeftOf="#id/item_clickable_pick_product_list_button_splitter_right"
android:layout_marginTop="8dp"
android:textColor="#color/black"
android:textSize="16sp"
android:lines="1"
android:ellipsize="marquee"
android:text="05-06-001-020111" />
<TextView
android:id="#+id/item_clickable_pick_product_list_button_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/item_clickable_pick_product_list_button_sku_title"
app:layout_constraintLeft_toRightOf="#id/item_clickable_pick_product_list_button_name_title"
app:layout_constraintRight_toLeftOf="#id/item_clickable_pick_product_list_button_splitter_right"
android:layout_marginTop="8dp"
android:textColor="#color/black"
android:textSize="16sp"
android:lines="2"
android:ellipsize="end"
android:text="这是一个两行的名称挺长的1231231231234511111111" />
<TextView
android:id="#+id/item_clickable_pick_product_list_button_process"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/item_clickable_pick_product_list_button_name_title"
app:layout_constraintLeft_toRightOf="#id/item_clickable_pick_product_list_button_process_title"
app:layout_constraintRight_toLeftOf="#id/item_clickable_pick_product_list_button_splitter_right"
android:layout_marginTop="8dp"
android:textColor="#color/red"
android:textSize="16sp"
android:text="0/20" />
</androidx.constraintlayout.widget.ConstraintLayout>
layout xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/activity_wms_multi_pick_dashboard_layout"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.originlinks.wmspda.activities.wms.pick.ProductListGridView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="#+id/activity_wms_multi_pick_dashboard_layout"
app:layout_constraintBottom_toBottomOf="#+id/activity_wms_multi_pick_dashboard_layout" />
</androidx.constraintlayout.widget.ConstraintLayout>
activity
public class DemoActivity extends ComponentActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityWmsMultiPickDashboardBinding binding = ActivityWmsMultiPickDashboardBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
}
}
I can see nothing showing in the design view but when I open my virtual device, the grid view is correcty showed.
How can I make the gridview visible in my design view? Is there any thing wrong with my code?

android showing MapView in a list

I tried to load a mapView in the listView for each item using baseAdaptor everything seems to be fine but maps(mapviews) are loading this way(the picture below is a single item of the list):
adapter class:
public class InfoAdapter extends BaseAdapter {
protected MapView mMapView;
GoogleMap googleMap;
Activity activity;
Bundle bundle;
Context context;
LayoutInflater layoutInflater;
ArrayList<Info> infos;
public TripsAdapter(Activity activity, Context context, ArrayList<Info> infos, Bundle bundle) {
this.context = context;
this.activity = activity;
this.layoutInflater = LayoutInflater.from(activity);
this.infos = infos;
this.bundle = bundle;
}
#Override
public int getCount() {
return infos.size();
}
#Override
public Object getItem(int i) {
return infos.get(i);
}
#Override
public long getItemId(int i) {
return i;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
if (view == null) {
view = layoutInflater.inflate(R.layout.list_infos_item, viewGroup, false);
view.findViewById(R.id.btnShare).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//share it
}
});
}
mMapView = (MapView) view.findViewById(R.id.fragment_embedded_map_view_mapview);
mMapView.onCreate(bundle);
return view;
}
}
the list_infos_item.xml is :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:map="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:padding="13dip">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="3dip"
android:padding="8.5dip"
android:elevation="5dp"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="5"
android:orientation="vertical">
<com.google.android.gms.maps.MapView
android:id="#+id/fragment_embedded_map_view_mapview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"/>
<LinearLayout
android:visibility="gone"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2">
</LinearLayout>
<Button
android:id="#+id/btnShare"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:layout_marginTop="12dip"
android:background="#color/yellow"
android:text="Share it!"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="#dimen/default_text_size" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
what is happening?how can I fix the problem?

ListView onItemClick() not called on API 23 only

My listview's onItemClick method is not being called when on API version 23. On version prior to that it's working great.
I've read about this issue Issue and it seems like it might relate. Any ideas?
The code is pretty straightforward, nothing fancy. It works on all version below API 23.
List item layout:
<TextView
android:id="#+id/history_member_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="#dimen/history_item_text_size" />
<TextView
android:id="#+id/operator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="#dimen/history_item_text_size" />
<TextView
android:id="#+id/history_member_B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="#dimen/history_item_text_size" />
<TextView
android:id="#+id/equal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text=" = "
android:textSize="#dimen/history_item_text_size" />
<TextView
android:id="#+id/history_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="#dimen/history_item_text_size" />
The layout the list sits in:
<?xml version="1.0" encoding="utf-8"?>
<keyboard.HistoryLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/history_layout"
android:layout_width="match_parent"
android:layout_height="#dimen/history_height"
android:animateLayoutChanges="true"
android:orientation="vertical">
<keyboard.HistoryView
android:id="#+id/history"
android:layout_width="match_parent"
android:layout_height="#dimen/history_height"
android:background="#android:color/white" />
</keyboard.HistoryLayout>
public class HistoryView extends ListView implements AdapterView.OnItemClickListener {
private HistoryAdapter mAdapter;
public HistoryView(Context context) {
super(context);
init();
}
public HistoryView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public HistoryView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
mAdapter = new HistoryAdapter();
setOnItemClickListener(this);
setAdapter(mAdapter);
}
#Override
protected void onFinishInflate() {
super.onFinishInflate();
}
public void loadHistory() {
ArrayList<CalculationItem> items = CalcManager.getInstance().getHistoryItems();
mAdapter.updateData(items);
}
public void update() {
mAdapter.notifyDataSetChanged();
smoothScrollToPosition(mAdapter.getCount() - 1);
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getContext(), "Clicked", Toast.LENGTH_SHORT).show();
}
}

Custom component Android LinearLayout not visible

Custom LinearLayout component view not displaying content
Hi i have created a custom component view that extends LinearLayout and when i use this view on my xml, it doesnt become visible on the screen.
Here is the main view that is using this custom component
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/contentLinearLayout"
android:layout_width="#dimen/width"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ABB0B6" />
<com.jon.ui.EnableView
android:id="#+id/enableContainter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Here is the EnableView custom component code:
package com.jon.ui;
/**
*/
public class EnableView extends LinearLayout {
private static View enableView;
private static Button btnContactlessInfoAction;
private static LinearLayout btnMakeContactlessAction;
private static View makeContactlessView;
private static View.OnClickListener enableContaclessBtnClick = new View.OnClickListener() {
#Override
public void onClick(View v) {
}
};
private static View.OnClickListener contactlessHelpBtnClick = new View.OnClickListener() {
#Override
public void onClick(View v) {
}
};
private static ViewGroup viewContainer;
private final Context mContext;
public EnableContactlessView(Context context) {
super(context);
mContext = context;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.custom_component, this);
setOrientation(LinearLayout.VERTICAL);
}
public EnableContactlessView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.custom_component, this);
setOrientation(LinearLayout.VERTICAL);
}
#Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
}
public void initiate() {
btnMakeContactlessAction = (LinearLayout) this.findViewById(R.id.btn);
btnContactlessInfoAction = (Button) this.findViewById(R.id.info_btn);
btnContactlessInfoAction.setOnClickListener(contactlessHelpBtnClick);
}
#Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
}
}
Below is the
View's layout xml i use to inflate from EnableView class called custom_component.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/top_margin"
android:gravity="center_horizontal"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="9dp"
android:layout_weight="3"
android:background="#color/button_colour"
android:gravity="center"
android:paddingBottom="9dp"
android:paddingTop="9dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:src="#drawable/icon_symbol" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="activate and enable"
android:textColor="#android:color/white" />
</LinearLayout>
<Button
android:id="#+id/info_btn"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical|end"
android:background="#drawable/icon" />
</LinearLayout>
Do not override onLayout if you're leaving it empty, remove that function. onLayout is used to measure the parent and its children, if you leave it empty nothing is getting measured.

I can't see ListFragment android?

I create a ListFragment for show Text & Image my code hase not any error but when i run it , it get me crash & when I see Log it don't get me any Message ?
My StartActivity.class :
public class StartActivity extends ActionBarActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
getSupportFragmentManager().beginTransaction().replace(R.id.main_container,new Setting_Fragment()).commit();
}
}
My activity_start.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/back"
tools:context="in.project.StartActivity" >
<ImageView
android:id="#+id/imgHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:background="#e42769"
android:src="#drawable/head" />
<LinearLayout
android:id="#+id/LFooter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="6" >
<ImageView
android:id="#+id/img_Setting_note"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/selector_setting_note" />
<ImageView
android:id="#+id/img_Calendar"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/selector_calendar" />
<ImageView
android:id="#+id/img_Mail"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/selector_mail" />
<ImageView
android:id="#+id/img_Review_note"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/selector_review_note" />
<ImageView
android:id="#+id/img_Help"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/selector_help" />
<ImageView
android:id="#+id/img_Setting"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="#drawable/selector_setting" />
</LinearLayout>
<FrameLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/LFooter"
android:layout_below="#+id/imgHeader" />
</RelativeLayout>
My SettingArrayAdapter.class :
public class SettingArrayAdapter extends ArrayAdapter<Instructure_setting>{
private Context context;
private List<Instructure_setting> objects;
public SettingArrayAdapter(Context context, int resource, List<Instructure_setting> objects) {
super(context, resource);
this.context = context;
this.objects = objects;
}
#SuppressLint({ "ViewHolder", "InflateParams" })
#Override
public View getView(int position, View convertView, ViewGroup parent) {
Instructure_setting _Data = objects.get(position);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.listview_setting_fragment, null);
ImageView image = (ImageView) view.findViewById(R.id.img_message);
image.setImageResource(_Data.getImageResource());
TextView tv = (TextView) view.findViewById(R.id.txt_message);
tv.setText(_Data.gettxtMessage());
return view;
}
}
My Setting_Fragment.class :
public class Setting_Fragment extends ListFragment{
List<Instructure_setting> DATA = new Setting_Fragment_Data().getMessages();
public Setting_Fragment()
{
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SettingArrayAdapter adapter = new SettingArrayAdapter(getActivity(),
R.layout.listview_setting_fragment,
DATA);
setListAdapter(adapter);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.setting_fragment, container, false);
return rootView;
}
}
My setting_fragment.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".StartActivity" >
<ListView
android:id="#+id/lstview_Setting_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</RelativeLayout>
My Setting_Fragment_Data.class :
public class Setting_Fragment_Data {
private List<Instructure_setting> _Messages = new ArrayList<Instructure_setting>();
public List<Instructure_setting> getMessages() {
return _Messages;
}
public Setting_Fragment_Data() {
_Messages.add(new Instructure_setting("AAA", R.drawable.period_color));
_Messages.add(new Instructure_setting("BBB", R.drawable.password_color));
_Messages.add(new Instructure_setting("CCC", R.drawable.cleare_data_color));
_Messages.add(new Instructure_setting("DDD", R.drawable.chanel_connect_color));
_Messages.add(new Instructure_setting("EEE", R.drawable.backup_color));
_Messages.add(new Instructure_setting("FFF", R.drawable.review_note_color));
_Messages.add(new Instructure_setting("GGG", R.drawable.notification_color));
_Messages.add(new Instructure_setting("HHH", R.drawable.sync_server_color));
}
}
My Instructure_setting.class :
public class Instructure_setting {
// constants for field references
public static final String TXT_Message = "TextMessage";
public static final String IMAGE_RESOURCE = "imageResource";
// private fields
private String txtMessage;
private int imageResource;
// getters and setters
public String gettxtMessage() {
return txtMessage;
}
public void settxtMessage(String txtMessage) {
this.txtMessage = txtMessage;
}
public int getImageResource() {
return imageResource;
}
public void setImageResource(int imageResource) {
this.imageResource = imageResource;
}
// Used when creating the data object
public Instructure_setting(String msg, int imageResource) {
this.txtMessage = msg;
this.imageResource = imageResource;
}
// Create from a bundle
public Instructure_setting(Bundle b) {
if (b != null) {
this.txtMessage = b.getString(TXT_Message);
this.imageResource = b.getInt(IMAGE_RESOURCE);
}
}
// Package data for transfer between activities
public Bundle toBundle() {
Bundle b = new Bundle();
b.putString(TXT_Message, this.txtMessage);
b.putInt(IMAGE_RESOURCE, this.imageResource);
return b;
}
// Output txtMessage data
#Override
public String toString() {
return txtMessage;
}
}
This is my listview_setting_fragment.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp">
<ImageView
android:id="#+id/img_message"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:contentDescription="placeholder" />
<TextView
android:id="#+id/txt_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/img_message"
android:text="placeholder"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
NOTICE : I am using from appcompat_v7 .
When you use ListFragment or ListActivity then ListView id in xml must be :
android:id="#id/android:list
Change your ListView id in xml :
<ListView
android:id="#id/android:list"
Instead of
<ListView
android:id="#+id/lstview_Setting_fragment"
Note : Try to set List Adapter in onCreateView() instead of onCreate() in Fragment.

Categories

Resources