The image in the imageview disappears from the scrollview in the ListView. How can i solve it?
public class IzahAdapter extends BaseAdapter {
private ArrayList<IzahVeriModeli> list;
LayoutInflater layoutInflater;
Context context;
holder Holder;
int pos;
public IzahAdapter(Context context, ArrayList<IzahVeriModeli> list) {
this.context = context;
// Layout Inflater tanımlanıyor...
this.list = list;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder=null;
View satirView = null;
Button bIngg, bTrr;
ImageView resimm = null;
//
if (convertView == null) {
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.listview_izahat, parent, false);
Holder = new holder();
Holder.resim = (ImageView) convertView.findViewById(resim);
Holder.bIng = (Button) convertView.findViewById(bIng);
Holder.bTr = (Button) convertView.findViewById(bTr);
Holder.bTr.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
pos = (Integer)v.getTag();
list.get(pos).setSelected(false);
System.out.println("pip2 = " + Integer.toString(pos));
notifyDataSetChanged();
}
});
Holder.bIng.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int pos = (Integer)v.getTag();
list.get(pos).setSelected(true);
System.out.println("pip3 = " + Integer.toString(pos));
notifyDataSetChanged();
}
});
convertView.setTag(Holder);
}
else {
Holder = (holder) convertView.getTag();
}
Holder.bTr.setTag(position);
Holder.bIng.setTag(position);
Holder.resim.setTag(position);
System.out.println("pip1 = " + position);
if (list.get(position).isSelected()) {
Holder.bTr.setVisibility(View.VISIBLE);
Holder.bIng.setVisibility(View.GONE);
notifyDataSetChanged();
} else {
Holder.bTr.setVisibility(View.GONE);
Holder.bIng.setVisibility(View.VISIBLE);
notifyDataSetChanged();
}
if (this.list.get(position).getResim()!=null)
{
Holder.resim.setImageBitmap(this.list.get(position).getResim2());
}
else
{
Holder.resim.getLayoutParams().width=0;
}
return convertView;
}
}
The image in Imageview comes from the data base. ImageView is shrinking if it is null, if not it adds image, but when i scroll the listview, things get messed up.
I did a lot of hard work, but i did not get resolved it.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="#drawable/satir_arkaplan"
android:orientation="horizontal"
android:padding="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="#+id/resim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:baselineAligned="false"
android:gravity="center_horizontal|center"
android:orientation="vertical"
android:padding="5dp">
<Button
android:id="#+id/bIng"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/ing"
android:textSize="9dp"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|center"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="5dp">
<Button
android:id="#+id/bTr"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|center"
android:background="#drawable/turk"
android:textSize="10dp" />
</LinearLayout>
Try something like that:
if (this.list.get(position).getResim()!=null) {
Holder.resim.setVisibility(View.Visible);
Holder.resim.setImageBitmap(this.list.get(position).getResim2());
}
else {
Holder.resim.setVisibility(View.Gone);
Holder.resim.setImageresource(0);
}
Related
I'm trying to build an android application,I have a 3 columns gridview that show a list of points,I want to jump to next line in a condition even when some of the columns are empty
Example I want to do something like this:
ARX ARH
BRH BRX BRY
CRH
DRH DRY
Try this One
your List item Row XML would be like this
Abc.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/darker_gray">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="5dp">
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="1"
android:gravity="center"
android:text="Name1"
android:textSize="18sp"
android:background="#android:color/white"
android:layout_margin="5dp"/>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="1"
android:gravity="center"
android:text="Name2"
android:textSize="18sp"
android:layout_margin="5dp"
android:background="#android:color/white"/>
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="1"
android:gravity="center"
android:text="Name3"
android:textSize="18sp"
android:layout_margin="5dp"
android:background="#android:color/white"/>
</LinearLayout>
</LinearLayout>
And CustomAdapter for List Would be like this
public class Custom_Adapter_Products extends BaseAdapter {
Context context;
String[] list = {"AAA","AAA","AAA","AAA","AAA","","AAA", "AAA","AAA"};
public Custom_Adapter_Products(Context context){
this.context = context;
}
#Override
public int getCount() {
return (list.length/3);
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int pos, View convertView, ViewGroup parent) {
try{
int position = (pos*3);
ViewHolder holder;
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
{
convertView = vi.inflate(R.layout.abc, null);
holder = createViewHolder(convertView);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
if(!list[position].equals("")){
holder.textView1.setText(list[position]);
holder.textView1.setVisibility(View.VISIBLE);
}
else{
holder.textView1.setVisibility(View.GONE);
}
if(!list[position+1].equals("")){
holder.textView2.setText(list[position]);
holder.textView2.setVisibility(View.VISIBLE);
}
else{
holder.textView2.setVisibility(View.GONE);
}
if(!list[position+2].equals("")){
holder.textView3.setText(list[position]);
holder.textView3.setVisibility(View.VISIBLE);
}
else{
holder.textView3.setVisibility(View.GONE);
}
}catch (Exception e){
e.printStackTrace();
}
return convertView;
}
private static class ViewHolder
{
public TextView textView1;
public TextView textView2;
public TextView textView3;
}
private ViewHolder createViewHolder(View v) {
ViewHolder holder = new ViewHolder();
try{
holder.textView1 = (TextView) v.findViewById(R.id.textView1);
holder.textView2 = (TextView) v.findViewById(R.id.textView2);
holder.textView3 = (TextView) v.findViewById(R.id.textView3);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return holder;
}
}
public class MyAdapter extends BaseAdapter implements ListAdapter {
private List<String> events = new ArrayList<String>();
private Context context;
public MyAdapter(List<String> events, Context context) {
this.events = events;
this.context = context;
String a = String.valueOf(events.size());
Toast.makeText(context,a,Toast.LENGTH_LONG).show();
}
#Override
public int getCount() {
return events.size();
}
#Override
public Object getItem(int position) {
return events.get(position);
}
#Override
public long getItemId(int position) {
//return events.get(position).getId();
return 0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.list_item_layout, null);
}
TextView listtv = (TextView) view.findViewById(R.id.label1);
listtv.setText(events.get(position));
Button delbutton = (Button) view.findViewById(R.id.del_button);
delbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(context,"You didn' code this feature yet",Toast.LENGTH_LONG).show();
}
});
return view;
}
}
I am creating an object of MyAdapter and calling it by passing a List and Activity.this
when i try to toast the size of the list passed i get the proper size
however only the first item of the list gets displayed on the screen
MY Xml`
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#00000000">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/label1"
android:padding="10dp"
android:textSize="15dp"
android:textStyle="bold"
android:gravity="center"
>
</TextView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/del_button"
android:background="#00000000"
android:drawableTop="#drawable/ic_close_black_24dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:paddingTop="10dp"
>
</Button>
</RelativeLayout>`
and my main layout file is
<RelativeLayout 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/content_cal_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.test123.CalView"
tools:showIn="#layout/activity_cal_view">
<ListView
android:id="#+id/list_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</ListView>
</RelativeLayout>
public static class ViewHolder{
public TextView listTV;
public Button delButton;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder holder;
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.list_item_layout, null);
//Edited this part
holder = new ViewHolder
holder.listTV = (TextView) view.findViewById(R.id.label1);
holder.delbutton = (Button) view.findViewById(R.id.del_button);
view.setTag(holder);
} else holder=(ViewHolder)view.getTag();
listtv.setText(events.get(position));
delbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(context,"You didn' code this feature yet",Toast.LENGTH_LONG).show();
}
});
return view;
}
When I try to click on EditText inside ListView item. It gains focus and loses focus, while debugging I found that if I clicked on 21st item, the position value changed like 21, 19, 1, 2 etc. Not sure if the list is re-rendering itself or something else is happening. I have already searched a lot and already tried configuring ListView (beforeDescendants and afterDescendants) and Activity (adjustPan).
I have used my custom adaptor. Sharing the XML file of ListView and list item along with java code of adapter.
XML list :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<!-- submit progress -->
<ProgressBar
android:id="#+id/list_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone"/>
<LinearLayout
android:id="#+id/list_form"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/nodata_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No data Found"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_gravity="center_horizontal"
android:textSize="20sp"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout
android:id="#+id/info_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal">
<Button
android:id="#+id/send_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create Order"
android:textSize="14sp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_weight="1"
android:textColor="#android:color/white"
android:background="#drawable/bg_button"/>
</LinearLayout>
<LinearLayout
android:id="#+id/ly_item_list_form"
android:layout_below="#+id/info_ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/item_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="afterDescendants"/>
</LinearLayout>
</RelativeLayout>
XML of list_item_selector
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
android:id="#+id/card_view"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="2dp"
card_view:cardPreventCornerOverlap="true"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:orientation="vertical">
<TextView
android:id="#+id/item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="ItemName"
android:textColor="#color/colorPrimaryDark"
android:textSize="15sp"
android:textStyle="bold"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:background="#FF0B38CC"></RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/uom_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="10dp"
android:text="uom"
android:textColor="#color/colorPrimary"
android:textSize="13sp"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal">
<ImageButton
android:id="#+id/button_minus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/ic_remove_black_24dp"/>
<EditText
android:id="#+id/number_of_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:gravity="center"
android:text="0"
android:digits="0123456789"
android:maxLength="4"
android:inputType="number"
android:textColor="#color/colorPrimary"/>
<ImageButton
android:id="#+id/button_plus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#null"
android:src="#drawable/ic_add_black_24dp"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
My custom Adaptor class
public class OrderViewListAdapter extends ArrayAdapter<OrderItemList> {
public OrderViewListAdapter(Context context, int resource) {
super(context, resource);
}
private class ViewHolder {
TextView sku_desc;
TextView uom_desc;
EditText order_qty;
ImageButton plus;
ImageButton minus;
AutoCompleteTextView uom;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// Get the data item for this position
OrderItemList vehicleTransit = mDataSet.get(position);
//System.out.println("kamal123" +mDataSet.get(position).getOrderID());
System.out.println("kamal123" +position);
ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.list_item_selector, parent, false);
viewHolder.sku_desc = (TextView) convertView.findViewById(R.id
.item_name);
viewHolder.uom_desc = (TextView) convertView.findViewById(R.id
.uom_desc);
viewHolder.order_qty = (EditText) convertView.findViewById(R.id.number_of_item);
viewHolder.plus= (ImageButton)convertView.findViewById(R.id.button_plus) ;
viewHolder.minus= (ImageButton)convertView.findViewById(R.id.button_minus) ;
convertView.setTag(viewHolder);
viewHolder.plus.setTag(viewHolder);
viewHolder.minus.setTag(viewHolder);
viewHolder.order_qty.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
if(vehicleTransit!= null) {
System.out.println("kamal123" + vehicleTransit.getExpectedDeliveryDate()
.toString());
if (vehicleTransit.getExpectedDeliveryDate() != null) {
viewHolder.uom_desc.setText(vehicleTransit.getUOMDesc()
.toString());
System.out.println("kamal123" +vehicleTransit.getExpectedDeliveryDate()
.toString());
}if (vehicleTransit.getSkuDesc() != null) {
viewHolder.sku_desc.setText(vehicleTransit.getSkuDesc().toString());
}
viewHolder.order_qty.setText(vehicleTransit.getOrderQty()+"");
viewHolder.order_qty.setId(position);
}
viewHolder.plus.setOnClickListener(new View.OnClickListener() {
int count=0;
#Override
public void onClick(View v) {
View p = (View) v.getParent();
ViewHolder holder1 = (ViewHolder) v.getTag();
count = Integer.valueOf(holder1.order_qty.getText().toString());
count++;
holder1.order_qty.setText(String.valueOf(count));
mDataSet.get(position).setOrderQty(count);
//mAdapter.notifyDataSetChanged();
}
});
viewHolder.minus.setOnClickListener(new View.OnClickListener() {
int count=0;
#Override
public void onClick(View v) {
View p = (View) v.getParent();
ViewHolder holder1 = (ViewHolder) v.getTag();
count = Integer.valueOf(holder1.order_qty.getText().toString());
count--;
if(count>=0)
{holder1.order_qty.setText(String.valueOf(count));
mDataSet.get(position).setOrderQty(count);
//mAdapter.notifyDataSetChanged();
}
}
});
//we need to update adapter once we finish with editing
viewHolder.order_qty.setOnFocusChangeListener(new View.OnFocusChangeListener() {
int count=0;
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus){
View p = (View) v.getParent();
ViewHolder holder1 = (ViewHolder) v.getTag();
final int position = holder1.order_qty.getId();
count = Integer.valueOf(holder1.order_qty.getText().toString());
if(count>0)
{holder1.order_qty.setText(String.valueOf(count));
mDataSet.get(position).setOrderQty(count);
//mAdapter.notifyDataSetChanged();
}
}
}
});
/*viewHolder.order_qty.addTextChangedListener(new TextWatcher() {
int count=0;
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
count = Integer.valueOf(s.toString());
mDataSet.get(position).setOrderQty(count);
}
});*/
return convertView;
}
#Override
public int getCount() {
return mDataSet.size();
}
}
Thanks in advance.
Insert this Line in onCreate before setContentView()
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST);
It will definitely help you
Finally, I figured it out. the problem was trying to solve get tex changed value inside getview. This was re-rendering the list items and I was getting wrong focus and different weird behavious. I have created a textwatcher class and added it while initializing the object, so that it doesn't affect everytime for each item in the list. Below is the code for MyCustom Adapter
public class OrderViewListAdapter extends ArrayAdapter<OrderItemList> {
public OrderViewListAdapter(Context context, int resource) {
super(context, resource);
}
private class ViewHolder {
TextView sku_desc;
TextView uom_desc;
EditText order_qty;
ImageButton plus;
ImageButton minus;
AutoCompleteTextView uom;
MyCustomEditTextListener myCustomEditTextListener;
public ViewHolder(View convertView, MyCustomEditTextListener myCustomEditTextListener) {
this.myCustomEditTextListener = myCustomEditTextListener;
this.order_qty = (EditText) convertView.findViewById(R.id.number_of_item);
this.order_qty.addTextChangedListener(myCustomEditTextListener);
}
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// Get the data item for this position
OrderItemList vehicleTransit = mDataSet.get(position);
//System.out.println("kamal123" +mDataSet.get(position).getOrderID());
System.out.println("kamal123" +position);
ViewHolder viewHolder;
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.list_item_selector, parent, false);
viewHolder = new ViewHolder(convertView, new MyCustomEditTextListener());
viewHolder.sku_desc = (TextView) convertView.findViewById(R.id
.item_name);
viewHolder.uom_desc = (TextView) convertView.findViewById(R.id
.uom_desc);
viewHolder.order_qty = (EditText) convertView.findViewById(R.id.number_of_item);
viewHolder.plus= (ImageButton)convertView.findViewById(R.id.button_plus) ;
viewHolder.minus= (ImageButton)convertView.findViewById(R.id.button_minus) ;
convertView.setTag(viewHolder);
viewHolder.plus.setTag(viewHolder);
viewHolder.minus.setTag(viewHolder);
viewHolder.order_qty.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
if(vehicleTransit!= null) {
System.out.println("kamal123" + vehicleTransit.getExpectedDeliveryDate()
.toString());
if (vehicleTransit.getExpectedDeliveryDate() != null) {
viewHolder.uom_desc.setText(vehicleTransit.getUOMDesc()
.toString());
System.out.println("kamal123" +vehicleTransit.getExpectedDeliveryDate()
.toString());
}if (vehicleTransit.getSkuDesc() != null) {
viewHolder.sku_desc.setText(vehicleTransit.getSkuDesc().toString());
}
viewHolder.myCustomEditTextListener.updatePosition(position);
viewHolder.order_qty.setText(vehicleTransit.getOrderQty()+"");
viewHolder.order_qty.setId(position);
}
viewHolder.plus.setOnClickListener(new View.OnClickListener() {
int count=0;
#Override
public void onClick(View v) {
View p = (View) v.getParent();
ViewHolder holder1 = (ViewHolder) v.getTag();
count = Integer.valueOf(holder1.order_qty.getText().toString());
count++;
holder1.order_qty.setText(String.valueOf(count));
mDataSet.get(position).setOrderQty(count);
//mAdapter.notifyDataSetChanged();
}
});
viewHolder.minus.setOnClickListener(new View.OnClickListener() {
int count=0;
#Override
public void onClick(View v) {
View p = (View) v.getParent();
ViewHolder holder1 = (ViewHolder) v.getTag();
count = Integer.valueOf(holder1.order_qty.getText().toString());
count--;
if(count>=0)
{holder1.order_qty.setText(String.valueOf(count));
mDataSet.get(position).setOrderQty(count);
//mAdapter.notifyDataSetChanged();
}
}
});
return convertView;
}
private class MyCustomEditTextListener implements TextWatcher {
private int position;
public void updatePosition(int position) {
this.position = position;
}
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
// no op
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
if (!charSequence.toString().equals("")) {
mDataSet.get(position).setOrderQty(Integer.valueOf(charSequence.toString()));
} else {
mDataSet.get(position).setOrderQty(0);
}
}
#Override
public void afterTextChanged(Editable editable) {
// no op
}
}
#Override
public int getCount() {
return mDataSet.size();
}
}
I currently have ListFragment with a ArrayAdapter class
The codes are below.
1)I want to implement a checkbox from listview main xml to check all the checkboxes that are present in custom list row xml which is inflated using Array adapter.
2)how to refresh view in this code by clearing all checkboxes when a button is clicked.
listview_main.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="match_parent"
android:orientation="vertical"
android:weightSum="10"
android:background="#fff2fff2" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="10"
android:choiceMode="multipleChoice" >
</ListView>
<TextView
android:id="#android:id/empty"
android:layout_width="wrap_content"
/>
<LinearLayout
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="#+id/btnin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="In" />
<Button
android:id="#+id/btndelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/checkAll"
android:checked="false" />
</LinearLayout>
</RelativeLayout>
custom_row.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" >
<ImageView
android:id="#+id/icon"
android:layout_width="50dp"
android:layout_height="50dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/paackage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent">
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Adapter class
public class FileAdapter extends ArrayAdapter<String>{
private List<String> filelist = null;
private Context context;
CheckBox checkAll;
public FileAdapter(Context _context, int _resource,List<String> _filelist) {
super(_context,_resource,_filelist);
this.context = _context;
this.filelist = _filelist;
this.itemChecked = new boolean[_filelist.size()];
}
private class ViewHolder {
TextView Name;
TextView pName;
CheckBox ck1;
ImageView iconview;
}
#Override
public int getCount() {
return ((null != filelist) ? filelist.size() : 0);
}
#Override
public String getItem(int position) {
return ((null != filelist) ? filelist.get(position) : null);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
View view = convertView;
if (null == view) {
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.custom_row, null);
holder = new ViewHolder();
holder.Name = (TextView) view.findViewById(R.id.name);
holder.pName = (TextView) view
.findViewById(R.id.paackage);
holder.ck1 = (CheckBox) view.findViewById(R.id.checkBox1);
holder.iconview = (ImageView) view.findViewById(R.id.app_icon);
view.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.appName.setText();
holder.packageName.setText();
holder.iconview.setImageDrawable();
holder.ck1.setChecked(false);
if (itemChecked[position])
holder.ck1.setChecked(true);
else
holder.ck1.setChecked(false);
holder.ck1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (holder.ck1.isChecked()) {
itemChecked[position] = true;
} else {
itemChecked[position] = false;
}
}
});
return view;
}
}
ListFragment class
public class FragmentA extends ListFragment implements View.OnClickListener {
public ArrayList<String> filelist;
Button in, delete;
ListView lv;
CheckBox cb;
private FileAdapter listadaptor = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
filelist = new ArrayList<String>();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View inflatedView = inflater.inflate(R.layout.fragment_app_restore, container, false);
in = (Button) inflatedView.findViewById(R.id.btnin);
delete= (Button) inflatedView.findViewById(R.id.btndelete);
lv = (ListView) inflatedView.findViewById(android.R.id.list);
empty = inflatedView.findViewById(android.R.id.empty);
//calling asynctask to load files here
delete.setOnClickListener(this);
in.setOnClickListener(this);
return inflatedView;
}
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
cb = (CheckBox) v.findViewById(R.id.checkBox1);//this is the checkbox in row only
cb.performClick();
if (cb.isChecked()) {
} else {
}
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btndelete:
break;
case R.id.btnin:
break;
}
}
private class LoadFiles extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
filelist = GetFiles(root_path);
if (filelist != null) {
listadaptor = new AppRestoreFileAdapter(getActivity(),
R.layout.custom_row, filelist);
} else {
// lv.setEmptyView(empty);
}
return null;
}
#Override
protected void onPostExecute(Void result) {
lv.setAdapter(listadaptor);
progress.dismiss();
super.onPostExecute(result);
}
}
}
I request you just see this video you will know what is the issue
https://www.youtube.com/watch?v=gsZSMRPEZSI&feature=youtu.be
Gridview scrolls and Gone when I scroll it's item
This issue is not occurring when there is limited no. of items in GridView or when we scroll slowly
I have taken Custom GridView, in that I am loading images and text from server
below is the code
GridView's XML file
<?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="match_parent"
android:background="#color/background" >
<TextView
android:id="#+id/edtTxtProfileQuotes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/small_margin"
android:background="#drawable/blue_notification_shape"
android:drawableLeft="#drawable/blue_notification_icon"
android:drawablePadding="#dimen/small_margin"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/light_violet" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:src="#drawable/teambg" />
<GridView
android:id="#+id/grdGrupOfUnite"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottomBar"
android:layout_below="#id/edtTxtProfileQuotes"
android:numColumns="3" >
</GridView>
</RelativeLayout>
Adapter's xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:orientation="vertical" >
<com.example.achessapp.widget.CircularImageView
android:id="#+id/ivUniteGrpMemIcon"
android:layout_width="#dimen/icon_size"
android:layout_height="#dimen/icon_size"
android:layout_centerHorizontal="true"
android:src="#android:color/white" />
<TextView
android:id="#+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/ivUniteGrpMemIcon"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/extra_small_margin"
android:layout_marginBottom="#dimen/small_margin"
android:gravity="center_horizontal"
android:textColor="#android:color/black" />
</RelativeLayout>
in Activity File
adapter = new BondMemberAdapter(mActivity, list_members_bean);
mGridMembers.setAdapter(adapter);
In Adapter file
public class BondMemberAdapter extends BaseAdapter {
LayoutInflater mInflator;
Activity mActivity;
private ArrayList<MembersBean> list_members_bean;
Typeface tf = null;
public BondMemberAdapter(Activity activity, ArrayList<MembersBean> list) {
mActivity = activity;
mInflator = LayoutInflater.from(mActivity);
list_members_bean = list;
tf = Typeface.createFromAsset(
mActivity.getAssets(), Constants.FONT_TYPE);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return list_members_bean.size();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
MembersBean bean = list_members_bean.get(position);
if (convertView == null) {
convertView = mInflator.inflate(R.layout.unite_grup_member_item,
null);
viewHolder = new ViewHolder();
viewHolder.ivUser = (CircularImageView) convertView
.findViewById(R.id.ivUniteGrpMemIcon);
viewHolder.tvName = (TextView) convertView
.findViewById(R.id.tvName);
viewHolder.tvName.setTypeface(tf);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
String text = "";
text = bean.getScreen_name();
//viewHolder.ivUser.setImageResource(R.drawable.unite_item);
if (bean.getThumbnail_url() != null) {
if (bean.getThumbnail_url().equals("null")) {
ImageLoader.getInstance().displayImage(
"drawable://" + R.drawable.profile_placeholder,
viewHolder.ivUser);
} else {
ImageLoader.getInstance().displayImage(bean.getThumbnail_url(),
viewHolder.ivUser);
}
}
else {
ImageLoader.getInstance().displayImage(
"drawable://" + R.drawable.profile_placeholder,
viewHolder.ivUser);
}
viewHolder.tvName.setText(text);
return convertView;
}
static class ViewHolder {
CircularImageView ivUser;
TextView tvName;
int position;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list_members_bean.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
}