import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
/**
* Demo Activity that will display the ListView and footer.
* @author techin
*/
public class Demo extends Activity {
ListView listView;
TextView textView;
String array[]=new String[]{"a","b","c","d","e","f","g","h","i"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView = (ListView)findViewById(R.id.ListView01);
textView = (TextView)findViewById(R.id.TextView01);
/**
* Setting ListView adapter using AttayAdapter.
*/
listView.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,array));
/**
* Implementing On click event of the ListView getting the item that is clicked.
*/
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(Demo.this,"Position"+arg2, Toast.LENGTH_SHORT).show();
textView.setText(array[arg2]);
}
});
}
}
Pages
▼

No comments:
Post a Comment