Set6Activity.java
package ps.set6;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
public class Set6Activity extends Activity implements OnItemClickListener {
/**
* www.master-gtu.blogspot.com
* pankaj sharma (8460479175)
* vijay chavda (8460420769)
*/
String flags[]={"india","bhutan","nepal","japan"};
int id[]={R.drawable.india,R.drawable.bhutan,R.drawable.nepal,R.drawable.japan};
ListView lv;
ImageView img;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv=(ListView) findViewById(R.id.listView1);
img=(ImageView) findViewById(R.id.imageView1);
ArrayAdapter<String>aa=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,flags);
lv.setAdapter(aa);
lv.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
img.setImageResource(id[arg2]);
}
}
No comments:
Post a Comment