-1

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;
    }
Ravi
  • 95
  • 1
  • 2
  • 9
  • You need to add a `TextWatcher` for each view where you want to do something as soon as the text changes. Then if it is editview 1, add text to tv1 etc if it is editview 2 add text to tv2... – nem035 Sep 23 '14 at 12:39
  • i used it see my code – Ravi Sep 23 '14 at 12:40
  • Please remove all unrelated code - and only leave in the parts of the code the are relevant. – Aleks G Sep 23 '14 at 12:42
  • read my question what i want to do.. – Ravi Sep 23 '14 at 12:43
  • the whole code is important.. – Ravi Sep 23 '14 at 12:44
  • @Ravi I read your question and re-read it again and, frankly, I don't quite understand what you're after. What I do see is that you dumped your entire activity code in the question whereas there's probably about 10 lines that are relevant to your question. – Aleks G Sep 23 '14 at 12:44
  • ok what is want to do is that i want to show first custom list view record to second list view how to do this.. – Ravi Sep 23 '14 at 12:51

1 Answers1

0

It's hard to understand what you're trying to do, but one thing is clear: you don't seem to understand how listviews work. You cannot change display elements of the list view directly - you have to change the data behind the adapter and then call notifyDataSetChanged.

You need to have some data structure to keep the data for each of the list views. Inside the adapter for your first ListView you need to have a reference to the data structure for the adapter of the second ListView. Then, inside your text watcher, when you need to update something in the second list view, you need to modify the data inside that data structure for the second list view and call notifyDataSetChanged on it for the changes to be reflected on screen.

Obviously, you'll need to modify your second adapter (and specifically the getView method) to create a view based on the content of the data structure and the index of the row.

Aleks G
  • 56,435
  • 29
  • 168
  • 265