I have created two custom list view,first custom list view has two text view and one edit text ,and in second custom list view there is three text view,what i want to do is that when user enter the value in first edit text,the value of that edit text with two text view record should show in second custom list view in first row,when user enter the value in second edit text the vale of that edit text with two text view record should show in second row of second list view,in my code when i enter the value in edit text the value of that edit text and both two text view record show i second list view but,when i enter the value in second edit text of first custom list view that value also show in second custom list view but it show in first row,I want to show that record in second row of second custom list view.
public class MainActivity extends Activity {
ArrayList<Candy> myArrList;
EditText text;
List<String> a = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myArrList = new ArrayList<Candy>();
ListView lisView1 = (ListView)findViewById(R.id.listView1);
ListView lisView2 = (ListView)findViewById(R.id.listView2);
myArrList.add(new Candy("Butterscotch", "10"));
myArrList.add(new Candy("Birthday Cake", "100"));
myArrList.add(new Candy("Black Crunch", "102"));
myArrList.add(new Candy("Industrial Chocolate", "200"));
myArrList.add(new Candy("Coffee Molasses Chip", "500"));
lisView1.setAdapter(new CountryAdapter(this));
lisView2.setAdapter(new CountryAdapter2(getApplicationContext()));
}
//This is base adapter for first list view
public class CountryAdapter extends BaseAdapter
{
private Context context;
public CountryAdapter(Context c)
{
context = c;
}
public int getCount() {
// TODO Auto-generated method stub
return myArrList.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.activity_mmnue, null);
}
// ColID
TextView txtID = (TextView) convertView.findViewById(R.id.nm);
txtID.setText(myArrList.get(position).getName() +".");
// ColCode
TextView txtCode = (TextView) convertView.findViewById(R.id.rat);
txtCode.setText(myArrList.get(position).getRate());
text = (EditText)convertView.findViewById(R.id.txtInput);
text.addTextChangedListener(new TextWatcher() {
@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) {
}
@Override
public void afterTextChanged(Editable s)
{
TextView txtCode = (TextView)findViewById(R.id.secnm);
TextView txtID = (TextView)findViewById(R.id.secrat);
TextView tv = (TextView)findViewById(R.id.sectxtInput);
txtCode.setText(myArrList.get(position).getName() +".");
tv.setText(s);
txtID.setText(myArrList.get(position).getRate());
Toast.makeText(getApplicationContext(), "hello"+s+""+myArrList.get(position).getName()+""+myArrList.get(position).getRate(), 50).show(); }
});
return convertView;}}
//This is second adapter for second list view
public class CountryAdapter2 extends BaseAdapter
{
private Context context;
public CountryAdapter2(Context c)
{
context = c;
}
public int getCount() {
//TODO Auto-generated method stub
return myArrList.size();
}
public Object getItem(int position) {
//TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
//TODO Auto-generated method stub
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
{convertView = inflater.inflate(R.layout.secmmnue, null);
}
return convertView;
}