Please Help to Solve My Issue !!
In the Activity there is a listview and A Button
ListView Row contains a TextView which displays the Serial No and 3 Edittexts (in which values will be entered)
The button Adds another row to the List.
I used my own class MemberEntry.
Problem is that In listview, data is entered smoothly but on scrolling
the textview value (Serial No.) remains fine but
the value of edittext (All 3) changes(The value of some other Edittext from the list takes place of another one).
I used this and found a little bit good results. But Not Accurate.
Code
Activity
OnCreate
MemberEntry m = new MemberEntry();
memberEntries = new ArrayList<>();
memberEntries.add(m);
adapter = new CustomListViewAdapter3(this, R.layout.row_entry_member, memberEntries);
LVMembers.setAdapter(adapter);
OnClick of a button
public void fab(View view) {
memberEntries.add(new MemberEntry());//memberEntries and adapter are global
adapter.notifyDataSetChanged();
}
Adapter
public class CustomListViewAdapter3 extends ArrayAdapter<MemberEntry> {
Context context;
int layoutResourceId;
public String[] Current;
ArrayList<MemberEntry> data = new ArrayList<>();
public static HashMap<Integer,String> myListOfNames=new HashMap<Integer,String>();
public CustomListViewAdapter3(Context context, int layoutResourceId,
ArrayList<MemberEntry> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
Current=new String[50];
this.data = data;
Log.d("CustomListViewAdapter", "Data = " + data + "\n Data Length = " + data.size() + "\n getCount=" + getCount());
for(int i=0;i<50;i++)
{
myListOfNames.put(i,"");
}
}
#Override
public int getCount() {
if(data != null && data.size() != 0){
return data.size();
}
return 0;
}
#Override
public MemberEntry getItem(int position) {
// TODO Auto-generated method stub
return data.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public int getViewTypeCount() {
return 1;
}
#Override
public int getItemViewType(int position) {
return position;
}
#NonNull
#Override
public View getView(final int position, View convertView, #NonNull ViewGroup parent) {
View row = convertView;
final RecordHolder holder;
//d("CustomListViewAdapter","GetView() called");
MemberEntry m = data.get(position);
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new RecordHolder();
holder.TVMemNo = (TextView) row.findViewById(R.id.TVMemNo);
holder.ETName = (EditText) row.findViewById(R.id.ETName);
holder.ETMobileNo = (EditText) row.findViewById(R.id.ETMobile);
holder.ETDefaultShare = (EditText) row.findViewById(R.id.ETDefaultShare);
row.setTag(holder);
m.setBinded(true);
Log.w("Yo","M is now Binded");
//e("Row is NOT Null", "NOT NULL NOT NULL NOT NULL");
} else {
if(m.isBinded()) {
Log.w("Yo","M found Binded");
holder = (RecordHolder) row.getTag();
}else{
Log.w("Yo","M found unBinded");
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new RecordHolder();
holder.TVMemNo = (TextView) row.findViewById(R.id.TVMemNo);
holder.ETName = (EditText) row.findViewById(R.id.ETName);
holder.ETMobileNo = (EditText) row.findViewById(R.id.ETMobile);
holder.ETDefaultShare = (EditText) row.findViewById(R.id.ETDefaultShare);
row.setTag(holder);
Log.w("Yo","M is now Binded");
m.setBinded(true);
}
//e("Row is Null","NULL NULL NULL");
}
holder.ref = position;
holder.TVMemNo.setText("+ Add Member " + (position + 2));//don't think much about +2, answer well and i will give a +2 (from my friend's account)
holder.ETName.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s) {
Current[holder.ref] = s.toString();
myListOfNames.put(position,s.toString().trim());
}
});
holder.ETName.setText(myListOfNames.get(position));
m.setRow(row);
data.set(position, m);
Log.d("Hi", "Added A Row");
return row;
}
//Log.e("Logger", "Position=" + position);
public ArrayList<MemberEntry> getEntries() {
return data;
}
static class RecordHolder {
//TextView TVRequestSent;
TextView TVMemNo;
EditText ETName, ETMobileNo, ETDefaultShare;
int ref;
}
}
row_entry_member.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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginBottom="15dp"
android:layout_marginTop="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight=".3"
android:orientation="horizontal">
<TextView
android:id="#+id/TVMemNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_weight="1.6"
android:gravity="left"
android:text="+ Add Member 2"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#4285F4"
android:textStyle="bold" />
<TextView
android:id="#+id/textView96"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="right"
android:text="(if Require) Default Share %"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#4285F4" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="1.8"
android:gravity="center_horizontal"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/textInpuitLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/textInputLayout"
android:layout_weight="1">
<EditText
android:id="#+id/ETName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="left"
android:hint="Name"
android:inputType="textPersonName"
android:maxLength="15"
android:textColor="#33691e" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/texjtInpuitLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/textInputLayout"
android:layout_weight="1.2">
<EditText
android:id="#+id/ETMobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="left"
android:hint="Mobile No."
android:inputType="number"
android:maxLength="10"
android:textColor="#33691e" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/textInpjuitLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/textInputLayout"
android:layout_weight="1.6">
<EditText
android:id="#+id/ETDefaultShare"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:layout_weight="1.4"
android:gravity="center"
android:hint=" %"
android:inputType="number"
android:maxLength="2"
android:textColor="#33691e" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
I have already searched on google but not getting proper accurate Solution.
Please Check My Code and Suggest best for me.
Related
In my android app I have listView with editTexts in it. I'm setting textIsSelectable for editTexts to false but text still stay selectable. For textViews everything work fine. Same result when I'm doing it programmatically in adapter.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/back"
android:clipToPadding="true"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_marginStart="10dp"
android:elevation="1dp"
android:layout_marginEnd="10dp"
android:padding="10dp"
android:weightSum="10">
<TextView
android:id="#+id/key"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dip"
android:textColor="#color/colorPrimaryDark"
android:textSize="16sp"
android:layout_weight="7"
/>
<EditText
android:id="#+id/value"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#aaaaaa"
android:textIsSelectable="false"
android:inputType="none"
android:padding="2dip"
android:textSize="16sp"
android:background="#ffffff"
android:layout_weight="3"/>
<TextView
android:id="#+id/text_value"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/colorPrimaryDark"
android:textIsSelectable="true"
android:autoLink="all"
android:padding="2dip"
android:textSize="16sp"
android:layout_weight="3"
android:visibility="gone"/>
<ImageView
android:id="#+id/img"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_weight="3"
android:adjustViewBounds="true"
android:clickable="true"/>
</LinearLayout>
</RelativeLayout>
My custom adapter.
class MyListViewAdapter extends ArrayAdapter<KeyValueList>
{
private int layoutResource;
private String rowId = "-", string = "-";
private String pos = "0";
private String vallue;
private int i = 0;
MyListViewAdapter(Context context, int layoutResource, List<KeyValueList> keyValueList)
{
super(context, layoutResource, keyValueList);
this.layoutResource = layoutResource;
setDefaultsInt("first", 1, getContext());
}
#RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
#NonNull
#Override
public View getView(final int position, final View convertView, #NonNull ViewGroup parent)
{
KeyValueList keyValuelist = getItem(position);
View view = convertView;
if (view == null)
{
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
view = layoutInflater.inflate(layoutResource, null);
ViewHolder holder = new ViewHolder();
holder.textView = (TextView) view.findViewById(R.id.key);
holder.editText = (EditText) view.findViewById(R.id.value);
holder.text_value = (TextView) view.findViewById(R.id.text_value);
holder.imageView = (ImageView) view.findViewById(R.id.img);
view.setTag(holder);
}
final ViewHolder holder = (ViewHolder) view.getTag();
if(openEntry.isEditable)
{
holder.text_value.setVisibility(View.GONE);
holder.editText.setVisibility(View.VISIBLE);
}
if(!openEntry.isEditable)
{
holder.text_value.setVisibility(View.VISIBLE);
holder.editText.setVisibility(View.GONE);
}
if (holder.textWatcher != null)
holder.editText.removeTextChangedListener(holder.textWatcher);
holder.textWatcher = new TextWatcher()
{
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
}
#Override
public void afterTextChanged(Editable s)
{
if(!s.toString().equals(vallue))
{
if(getDefaultsInt("first",getContext()) == 1)
{
openEntry.edit_list.add(null);
setDefaultsInt("p", position, getContext());
setDefaultsInt("first", 0, getContext());
}
if(getDefaultsInt("p", getContext()) != position)
{
openEntry.edit_list.add(null);
i++;
setDefaultsInt("p", position, getContext());
}
try
{
rowId = getRowID(position);
string = s.toString();
pos = String.valueOf(position);
} catch (JSONException e)
{
e.printStackTrace();
}
HashMap<String, String> edit = new HashMap<>();
edit.put("rowID", rowId);
edit.put("string", string);
edit.put("position", pos);
openEntry.edit_list.set(i, edit);
}
}
};
holder.editText.addTextChangedListener(holder.textWatcher);
assert keyValuelist != null;
holder.textView.setText(keyValuelist.getKey());
vallue = keyValuelist.getValue();
if (vallue.length() != 0 && vallue.contains("printFile"))
{
final String durl = vallue.replace("printFile","file");
new DownloadImageTask(holder.imageView).execute(vallue);
holder.editText.setVisibility(View.GONE);
holder.text_value.setVisibility(View.GONE);
holder.imageView.setVisibility(View.VISIBLE);
holder.imageView.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Uri uriUrl = Uri.parse(durl);
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
getContext().startActivity(launchBrowser);
}
});
}
else
{
holder.editText.setText(vallue);
holder.text_value.setText(vallue);
}
return view;
}
et.setFocusable(false);
et.setTextIsSelectable(false);
//if clickble then true otherwise false
et.setClickable(true);
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();
}
}
My Custom adapter is as follows:-
public class ListAdapter extends ArrayAdapter<Person> implements SectionIndexer {
private HashMap<String, Integer> alphaIndexer;
private String[] sections;
public ListAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
public ListAdapter(Context context, int resource, ArrayList<Person> items) {
super(context, resource, items);
alphaIndexer = new HashMap<String, Integer>();
for (int i = 0; i < items.size(); i++)
{
Log.d("State",items.get(i).getState().substring(0, 1).toUpperCase());
String s = items.get(i).getState().substring(0, 1).toUpperCase();
alphaIndexer.put(s, i);
}
Set<String> sectionLetters = alphaIndexer.keySet();
ArrayList<String> sectionList = new ArrayList<String>(sectionLetters);
Collections.sort(sectionList);
sections = new String[sectionList.size()];
sectionList.toArray(sections);
}
public int getPositionForSection(int section)
{
return alphaIndexer.get(sections[section]);
}
public int getSectionForPosition(int position)
{
return 1;
}
public Object[] getSections()
{
return sections;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.bystate_itemview, null);
}
Person p = getItem(position);
if (p != null) {
ImageView im1= (ImageView) v.findViewById(R.id.legislator_image);
TextView tt1 = (TextView) v.findViewById(R.id.firstname);
TextView tt2 = (TextView) v.findViewById(R.id.details);
ImageView im2 = (ImageView) v.findViewById(R.id.getDetails);
if (im1 != null){
String url = p.getImage();
Picasso.with(getContext()).load(url).fit().centerCrop().into(im1);
}
if (tt1 != null) {
String name= p.getLastname()+", "+p.getFirstname();
tt1.setText(name);
}
if (tt2 != null) {
String details="";
if(p.getDistrict()!="NA")
details= "("+p.getParty()+")"+p.getState()+" - "+"District "+p.getDistrict();
else
details= "("+p.getParty()+")"+p.getState()+" - "+"District 0";
tt2.setText(details);
}
if (im2 != null) {
Drawable myDrawable = getResources().getDrawable(R.drawable.right);
im2.setImageDrawable(myDrawable);
}
}
return v;
}
}
I have implemented this custom adapter following a tutorial. I have implemented the section indexer. But the issue is that the section indexer does not show up in the app. I am trying to index stuff based on the first letter of each state of the person. I want the alphabetical list to show up in the list view so that when I tap on a particular letter it must show persons belonging to that state.
My xml files:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/state_listView"
android:layout_weight="1"
android:layout_marginTop="35dp"
android:fastScrollEnabled="true"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:layout_marginTop="40dp"
android:background="#drawable/gradient">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<ImageView
android:layout_width="55dp"
android:layout_height="49dp"
android:layout_margin="5dp"
android:id="#+id/legislator_image"
android:layout_weight="0.19"
android:layout_alignParentLeft="true"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="80dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:text="Medium Text"
android:id="#+id/firstname"
android:layout_marginTop="3dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/details"
android:layout_marginTop="3dp" />
</LinearLayout>
<ImageView
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginTop="20dp"
android:layout_marginRight="3dp"
android:layout_alignParentRight="true"
android:id="#+id/getDetails"/>
</RelativeLayout>
</LinearLayout>
Please let me know if I am missing something. This is my first custom adapter so I may be doing something wrong.
Just use below structure ,Mayi know why youimplement sectionIndex
public class CustomeAdapter extends BaseAdapter {
#Override
public int getCount() {
return 0;
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
return null;
}
}
I have grid view , on which each item consists of few images and text . When it loads for the first time , everything is fine but if I scroll to the bottom and the go back to top some two images are gone from a item , and it goes randomly .
here is the code for Grid view
<GridView
android:id="#+id/testR_grid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
android:columnWidth="#dimen/gridview_column_width"
android:horizontalSpacing="#dimen/grid_horizontal_spacing"
android:listSelector="#drawable/gridview_background"
android:numColumns="auto_fit"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:verticalScrollbarPosition="right"
android:verticalSpacing="#dimen/grid_vertical_spacing"
android:fastScrollEnabled="false"/>
Here the code for single item
<?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="250dp"
android:layout_marginTop="5dp"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/blurry_shadow_rect">
<com.joooonho.SelectableRoundedImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/item_image"
android:layout_width="match_parent"
android:layout_height="#dimen/gridview_column_width"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="-5dp"
app:sriv_left_bottom_corner_radius="0dip"
app:sriv_left_top_corner_radius="4dip"
app:sriv_right_bottom_corner_radius="0dip"
app:sriv_right_top_corner_radius="4dip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/item_image"
android:layout_marginBottom="5dp"
android:layout_marginLeft="2dp"
android:orientation="horizontal"
android:weightSum="100">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="35">
<TextView
android:id="#+id/item_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="start"
android:layout_marginBottom="5dp"
android:ellipsize="end"
android:fontFamily="sans-serif-light"
android:maxLines="1"
android:text=""
android:textColor="#color/bodyText"
android:textSize="#dimen/GridHeader" />
<TextView
android:id="#+id/item_TestA_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/item_text"
android:layout_marginBottom="10dp"
android:alpha=".5"
android:ellipsize="end"
android:maxLines="1"
android:text=""
android:textColor="#color/bodyText"
android:textSize="#dimen/GridHeader2" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="2dp"
android:layout_weight="65">
<TextView
android:id="#+id/item_testR_free_text"
style="#style/textview_grid_free_banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:fontFamily="sans-serif-light"
android:maxLines="1"
android:padding="2dp"
android:singleLine="true"
android:text=" FREE " />
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="#+id/already_owned"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:singleLine="true"
android:layout_marginLeft="20dp"
android:layout_marginBottom="5dp"
android:visibility="gone"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/ic_testR_bought_36dp" />
<ImageButton
android:id="#+id/item_testR_more_options"
android:layout_width="#dimen/image_button_more"
android:layout_height="#dimen/image_button_more"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/item_testR_free_text"
android:alpha=".5"
android:background="#drawable/imagebutton_background"
android:clickable="true"
android:focusable="false"
android:src="#drawable/ic_more_vert_black_24dp" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
The elements are randomly missing are text view which id is item_testR_free_text and imageview which id is already_owned . One thing also to be noted the visibility of these two items are conditional .
Here is my code for adapter
public class TestRGridViewAdapter extends ArrayAdapter<TestR> {
Context context;
int layoutResourceId;
List<TestR> data = new ArrayList<TestR>();
RecordHolder holder = null;
//DiskCache imgCache;
TestA TestA;
TestR item;
FragmentActivity mFragmentActivity;
boolean is_local = false;
List<Track> trackList;
public TestR getItem() {
return item;
}
public void setItem(TestR item) {
this.item = item;
}
public TestRGridViewAdapter(Context context, int layoutResourceId,
List<TestR> data, FragmentActivity mFragmentActivity, boolean is_local) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
this.mFragmentActivity = mFragmentActivity;
// imgCache = Parameters.imgCache;
this.is_local = is_local;
}
public TestRGridViewAdapter(Context context, int layoutResourceId,
List<TestR> data, FragmentActivity mFragmentActivity) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
this.mFragmentActivity = mFragmentActivity;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
//LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = LayoutInflater.from(context).inflate(layoutResourceId, null);
//row = inflater.inflate(layoutResourceId, parent, false);
holder = new RecordHolder();
holder.item_testR_free_text = (TextView) row.findViewById(R.id.item_testR_free_text);
holder.txtTitle = (TextView) row.findViewById(R.id.item_text);
holder.txtTestAName = (TextView) row.findViewById(R.id.item_TestA_name);
holder.imageItem = (SelectableRoundedImageView) row.findViewById(R.id.item_image);
holder.item_testR_more_options = (ImageButton) row.findViewById(R.id.item_testR_more_options);
holder.already_owned = (ImageView) row.findViewById(R.id.already_owned);
// holder.grid_swipe_refresh_layout = (SwipeRefreshLayout) row.findViewById(R.id.grid_swipe_refresh_layout);
row.setTag(holder);
} else {
holder = (RecordHolder) row.getTag();
}
item = data.get(position);
holder.txtTitle.setText(item.getName());
// else
// holder.txtArtitName.setText("");
//holder.imageItem.setImageBitmap(item.getImage());
try {
if (item.getTestA_id() == null)
item = new SaveData(context).get_online_testR(item.getTestR_id());
TestA = Helper.getDaoSession(context).getTestADao().load(item.getTestA_id());
if (TestA == null) {
TestA = new SaveData(context).get_save_TestA(item.getTestA_id());
}
// if (TestA != null)
holder.txtTestAName.setText((TestA != null) ? TestA.getName() : "");
// else
// TestA = new SaveData(context).get_save_TestA(item.getTestA_id());
if (!is_local) {
if(!DBQuery.is_owner(context,item.getTestR_id())) {
Log.d("test","not owner - "+item.getName());
holder.item_testR_free_text.setText(
UXHelper.getPriceFromString(Parameters.price_type.equals("local_price") ?
item.getLocal_price().toString() : item.getPrice().toString()));
holder.already_owned.setVisibility(View.INVISIBLE);
holder.item_testR_more_options.setOnClickListener(new testR_popup_onClick(context, item, holder.item_testR_more_options, mFragmentActivity, TestA));
}else {
Log.d("test","owner - "+item.getName());
holder.item_testR_free_text.setVisibility(View.INVISIBLE);
holder.already_owned.setVisibility(View.VISIBLE);
holder.item_testR_more_options.setOnClickListener(new testR_popup_onClick(context, item, holder.item_testR_more_options, mFragmentActivity, TestA));
}
} else {
Log.d("test","local - "+item.getName());
holder.already_owned.setVisibility(View.INVISIBLE);
boolean synced = true;
trackList = new ArrayList<Track>();
List<Track> trackListTmp = new SaveData(context).get_tracks_local(item.getTestR_id());
boolean testR_owner = DBQuery.is_owner(context, trackListTmp.get(0).getTestR_id());
for (Track t : trackListTmp) {
boolean track_owner = DBQuery.is_owner(context, t.getTrack_id(), t.getTestR_id());
if (track_owner)
trackList.add(t);
if (testR_owner || track_owner) {
if (t.getSynced_dir() == null) {
synced = false;
// break;
} else if (!new File(t.getSynced_dir()).exists()) {
synced = false;
// break;
}
}
}
if (synced) {
Log.d("test","synched - "+item.getName());
holder.item_testR_free_text.setVisibility(View.VISIBLE);
holder.item_testR_free_text.setText("Synced");
} else {
Log.d("test","not synched - "+item.getName());
holder.item_testR_free_text.setVisibility(View.INVISIBLE);
holder.item_testR_more_options.setOnClickListener(
new testR_popup_downloaded_onCLick(context, item, holder.item_testR_more_options, mFragmentActivity, TestA,
trackList.toArray(new Track[trackList.size()]), synced));
}
}
Target target = new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
holder.imageItem.setImageBitmap(bitmap);
}
#Override
public void onBitmapFailed(Drawable errorDrawable) {
holder.imageItem.setImageResource(R.drawable.ic_example_36);
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
holder.imageItem.setImageResource(R.drawable.ic_example_36);
}
};
if (Parameters.mPicasso == null)
Parameters.mPicasso = new Picasso.Builder(context)
.build();
Parameters.mPicasso.load("http://" + context.getString(R.string.ip) + "/" +
context.getString(R.string.TestRsController) + "/" + context.getString(R.string.TESTR_THUMB_URL)
+ "/" + item.getTestR_id()+"/"+Parameters.dpi)
.placeholder(R.drawable.ic_example_36)
.error(R.drawable.ic_example_36)
.into(holder.imageItem);
} catch (Exception ex) {
new Logger(context).appendLog("Error in TestR grid view item " + ex.getMessage());
}
return row;
}
static class RecordHolder {
// SwipeRefreshLayout grid_swipe_refresh_layout;
TextView txtTitle;
TextView txtTestAName;
SelectableRoundedImageView imageItem;
TextView item_testR_free_text;
ImageButton item_testR_more_options;
ImageView already_owned;
}
}
I couldn't select an item on ListView. I use Custom Adapter to set content of ListView. I have set OnItemClickListener of ListView. However, it didn't respond. I appriciate your help. Here is my code:
List Item (connections.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:orientation="horizontal"
android:padding="6dip" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.90"
android:orientation="vertical" >
<TextView
android:id="#+id/connname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/acc1" />
<TextView
android:id="#+id/conntype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="9sp"
android:text="#string/acctype1" />
</LinearLayout>
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
The screen which containt ListView (groupconnections.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">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:orientation="vertical"
android:id="#+id/textOperLayout">
<TextView
android:id="#+id/connectionsLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/connections"
android:textColor="#color/conn_text"
android:textSize="25sp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="15dp"
android:background="#color/conn_back"/>
<EditText
android:id="#+id/searchEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/searchhint"
android:layout_marginTop="10dp"
android:inputType="textPersonName" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dip"
android:layout_marginBottom="50dip"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_above="#+id/textOperLayout"
android:id="#+id/listviewlayout">
<ListView
android:id="#+id/connectionlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="singleChoice" />
</LinearLayout>
<Button
android:id="#+id/addConnCommitButton"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="15dp"
android:text="#string/commitToAdd" />
</RelativeLayout>
The related activity (AddMoreConnections.xml):
public class AddMoreConnections extends Activity implements OnItemClickListener{
private ListView mainListView ;
private ArrayAdapter<AbstractHolder> listAdapter ;
private TextView searchConnTextView;
private Button commitButton;
private ArrayList<AbstractHolder> connlist;
private ArrayList<AbstractHolder> listNotOnView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Generate list View from ArrayLis
setContentView(R.layout.groupconnections);
addListenerOnSearchConnTextView();
//Initialize properties
mainListView = (ListView) findViewById( R.id.connectionlist );
mainListView.setOnItemClickListener(this);
// Create and populate a List of planet names.
listNotOnView = new ArrayList<AbstractHolder>();
connlist = new ArrayList<AbstractHolder>(5);
Iterator<AbstractHolder> iter = SocialRssModel.holders.values().iterator();
while(iter.hasNext())
connlist.add(iter.next());
// Create ArrayAdapter using the planet list.
listAdapter = new CustomAdapter(this,
R.layout.connlist, connlist);
mainListView.setAdapter( listAdapter );
}
public void addListenerToFinishButton(){
commitButton = (Button) findViewById(R.id.addConnCommitButton);
commitButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
public void addListenerOnSearchConnTextView(){
searchConnTextView = (TextView) findViewById(R.id.searchEditText);
searchConnTextView.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
int listNotOnViewsize = listNotOnView.size();
int connlistsize = connlist.size();
for(int i= 0; i < connlistsize; i++){
if(!connlist.get(i).connNameContains(s.toString())){
listNotOnView.add(connlist.remove(i));
i--;
connlistsize--;
}
}
for(int i=0; i < listNotOnViewsize; i++){
if(listNotOnView.get(i).connNameContains(s.toString())){
connlist.add(listNotOnView.remove(i));
i--;
listNotOnViewsize--;
}
}
((CustomAdapter) listAdapter).updateList(connlist);
listAdapter.notifyDataSetChanged();
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void afterTextChanged(Editable s) {
}
});
}
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
AbstractHolder temp = (AbstractHolder)mainListView.getItemAtPosition(arg2);
Intent i = new Intent(this, CategoryContentViewerController.class);
Bundle b = new Bundle();
b.putInt("AbstractHolderKey", temp.getId());
i.putExtras(b);
startActivity(i);
finish();
}
private class CustomAdapter extends ArrayAdapter<AbstractHolder> {
private ArrayList<AbstractHolder> connectionList;
public CustomAdapter(Context context, int textViewResourceId, ArrayList<AbstractHolder> connList) {
super(context, textViewResourceId, connList);
this.connectionList = new ArrayList<AbstractHolder>();
this.connectionList.addAll(connList);
}
public void updateList(ArrayList<AbstractHolder> connList){
connectionList.clear();
connectionList.addAll(connList);
}
private class ViewHolder {
TextView name;
TextView acctype;
CheckBox sel;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
Log.v("ConvertView", String.valueOf(position));
if (convertView == null) {
LayoutInflater vi = (LayoutInflater)(((Activity)this.getContext()).getSystemService(Context.LAYOUT_INFLATER_SERVICE));
convertView = vi.inflate(R.layout.connlist, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.connname);
holder.acctype = (TextView) convertView.findViewById(R.id.conntype);
holder.sel = (CheckBox) convertView.findViewById(R.id.checkBox1);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
AbstractHolder conn = connectionList.get(position);
holder.name.setText(conn.getName());
holder.acctype.setText(conn.getConntype());
holder.sel.setChecked(conn.isSelected());
holder.sel.setTag(conn);
return convertView;
}
}
}
It is related to checkbox item in connections.xml which is the list row item. If I remove checkbox, related listeners responses. I think, it may be thought there is no need a setItemOnClickListener(..) method since each row has a checkbox. Or it is a bug.