public class MainActivity extends Activity { ListView list; String[] abc={"1","2","3"}; MyCustomAdapter adapter; Button refresh; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list=(ListView) findViewById(R.id.list); refresh=(Button) findViewById(R.id.refresh); adapter=new MyCustomAdapter(MainActivity.this,abc); list.setAdapter(adapter); } private class MyCustomAdapter extends BaseAdapter { private final Context context; private ArrayList mData = new ArrayList(); private LayoutInflater mInflater; private String[] hashmap; ViewHolder holder = null; public MyCustomAdapter(Context context,String[] hashMaps) { super(); this.context = context; this.hashmap = hashMaps; mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public int getCount() { return hashmap.length; } public Object getItem(int position) { return hashmap.length; } public long getItemId(int position) { return position; } @Override public void notifyDataSetChanged()
View.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:id="@+id/real" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:text="Text" android:layout_marginTop="15dp" android:layout_marginLeft="20dp" /> <Button android:id="@+id/refresh" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/text" android:text="button" android:layout_marginLeft="20dp" /> </RelativeLayout>
Here, in my ListView, when I click the button, the value does not change inside my view.how adapter to solve this? the list contains 3 values โโof each item. When I press the button in the pressed position, the value will change instead of the old value.
source share