I'm trying to get the text from edittext to the listview. i have already added an image and textview in listview. now i need to know how to get the data from edittext and apply in listview. I'm adding my codes below :
activity class:
public class MainActivity extends ActionBarActivity {
int[] image={R.drawable.confidential};
String[] web = new String[] {"1","2"};
Integer[] imageId = {
R.drawable.confidential,R.drawable.confidential1};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText ed =(EditText) findViewById(R.id.editText1);
Button bt=(Button) findViewById(R.id.button1);
//final Typeface custom_font = Typeface.createFromAsset(getAssets(), "font/d.ttf");
// String ts1 = ed.getText().toString();
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// String ts1 = ed.getText().toString();
// tx.setText(ts1);
// tx.setTypeface(custom_font);
CustomList adapter = new
CustomList(MainActivity.this, web, imageId);
ListView list=(ListView)findViewById(R.id.listView1);
list.setAdapter(adapter);
}
});
}}
my adapter class:
public class CustomList extends ArrayAdapter<String>{
private final Activity context;
private final String[] web;
private final Integer[] imageId;
public CustomList(Activity context,String[] web, Integer[] imageId) {
super(context, R.layout.list, web);
this.context = context;
this.web = web;
this.imageId = imageId;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.list, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
ImageView imageView = (ImageView) rowView.findViewById(R.id.imageview);
txtTitle.setText(web[position]);
imageView.setImageResource(imageId[position]);
return rowView;
}
}
please help me with sample codes..!! thank you!