Android : how to show only record which is edited in edittext of first custom listview

on Tuesday, September 16, 2014


I want to show only record which are edited in first custom listview,and also show it whole row record in second custom listview.in first custom listview there is two textview and one edittext and in second custom listview there is two textview and one edittext..



public class Mmnue extends Activity {
ArrayList<gtsty> myArrList;
ArrayList<String> editTextValues;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.menuitem);
//CountryAdapter2 newAdpt = null;
myArrList = new ArrayList<gtsty>();
editTextValues = new ArrayList<String>();
final ListView lisView1 = (ListView)findViewById(R.id.listView1);
final ListView lisView2 = (ListView)findViewById(R.id.listView2);

myArrList.add(new gtsty("Butterscotch", "Rs 10"));
myArrList.add(new gtsty("Birthday Cake", "Rs 100"));
myArrList.add(new gtsty("Black Crunch", "Rs 102"));
myArrList.add(new gtsty("Industrial Chocolate", "Rs 200"));
myArrList.add(new gtsty("Coffee Molasses Chip", "Rs 500"));

lisView1.setAdapter(new CountryAdapter(this));

Button btnGetItem = (Button) findViewById(R.id.btnGetItem);
btnGetItem.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
int count = lisView1.getAdapter().getCount();
for(int i=0;i<count;i++)
{
LinearLayout itemLayout = (LinearLayout)lisView1.getChildAt(i);

EditText text = (EditText)itemLayout.findViewById(R.id.txtInput);
String value = text.getText().toString();
editTextValues.add(value);
Toast.makeText(getApplicationContext(),""+value, Toast.LENGTH_LONG).show();
}
lisView2.setAdapter(new CountryAdapter2(getApplicationContext()));
}
});
}
public class CountryAdapter extends BaseAdapter
{
private Context context;
public CountryAdapter(Context c)
{
//super( c, R.layout.activity_column, R.id.rowTextView, );
// TODO Auto-generated method stub
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).getID() +".");
// ColCode
TextView txtCode = (TextView) convertView.findViewById(R.id.rat);
txtCode.setText(myArrList.get(position).getCode());
return convertView;

}
}
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) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

if (convertView == null)
{convertView = inflater.inflate(R.layout.secmmnue, null);
}

// ColID
TextView txtID = (TextView) convertView.findViewById(R.id.secnm);
txtID.setText(myArrList.get(position).getID() +".");
// ColCode
TextView txtCode = (TextView) convertView.findViewById(R.id.secrat);
txtCode.setText(myArrList.get(position).getCode());

TextView tv = (TextView)convertView.findViewById(R.id.sectxtInput);
tv.setText(editTextValues.get(position).toString());
return convertView;
}
}

0 comments:

Post a Comment