Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package home.customList;
- import android.app.ListActivity;
- import android.content.Context;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.View.OnClickListener;
- import android.widget.ArrayAdapter;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.ListView;
- import android.widget.TextView;
- import android.widget.Toast;
- public class Main extends ListActivity{
- String[] countries;
- int c=0;
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- countries = getResources().getStringArray(R.array.countries_array);
- //Toast.makeText(this,"Main class",Toast.LENGTH_LONG).show();
- Log.d("------------main class-----------", "start");
- setListAdapter(new MyAdapter(this,android.R.layout.simple_list_item_1,R.id.textView1,countries));
- //Toast.makeText(this,"end of Main class",Toast.LENGTH_LONG).show();
- Log.d("------------main class-----------", "end");
- ListView listView = getListView();//getListView() from ListActivity //public class ListView
- //listView.setTextFilterEnabled(true);
- }
- private class MyAdapter extends ArrayAdapter<String>
- {
- public MyAdapter(Context context, int resource, int textViewResourceId,String[] strings)
- {
- //Toast.makeText(Main.this,"getView() row="+c,Toast.LENGTH_LONG).show();
- super(context, resource, textViewResourceId, strings);
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent)
- {
- c++;
- //Toast.makeText(Main.this,"getView() c="+c,Toast.LENGTH_LONG).show();
- Log.d("------------getView()-----------c="+c, "c="+c);
- LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View row=inflater.inflate(R.layout.list_item,parent,false);
- String[] items=getResources().getStringArray(R.array.countries_array);
- ImageView iv=(ImageView) row.findViewById(R.id.imageView1);
- TextView tv=(TextView) row.findViewById(R.id.textView1);
- EditText et=(EditText)row.findViewById(R.id.editText1);
- CheckBox cb=(CheckBox)row.findViewById(R.id.checkBox1);
- tv.setText(items[position]);
- et.setText("my button");
- cb.setClickable(true);
- if(items[position].equals("bangladesh"))
- {
- iv.setImageResource(R.drawable.bangladesh);
- }
- else if(items[position].equals("england"))
- {
- iv.setImageResource(R.drawable.england);
- }
- else if(items[position].equals("usa"))
- {
- iv.setImageResource(R.drawable.usa);
- }
- else if(items[position].equals("russia"))
- {
- iv.setImageResource(R.drawable.russia);
- }
- else
- {
- iv.setImageResource(R.drawable.ic_launcher);
- }
- tv.setOnClickListener(new OnClickListener() {
- public void onClick(View v)
- {
- Toast.makeText(getApplicationContext(),((TextView)v).getText(), Toast.LENGTH_SHORT).show();
- }
- });
- Log.d("------------row=-----------"+row, "row="+row);
- return row;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement