这是我的代码,
public class SecondScreenActivity extends Activity {
ListView foodJntListView;
ArrayList<Restaurent> restaurentData;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.second_screen);
restaurentData = getFoodJnt();
foodJntListView=(ListView)findViewById(R.id.listView_foodjnt);
foodJntListView.bringToFront();
// setting the adapter to the list
foodJntListView.setAdapter(new RestaurantBaseAdapter(this,restaurentData));
//setting the onclick listener,activity on clicking on an item of the
foodJntListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
String hotelname=restaurentData.get(position).toString();
//things to write
}
});
}
// get all the list of foodjoints
private ArrayList<Restaurent> getFoodJnt() {
// TODO Auto-generated method stub
ArrayList<Restaurent> results=new ArrayList<Restaurent>();
Restaurent restrnt=new Restaurent();
restrnt.setFoodJointname("Ashila");
restrnt.setCuisine("Biriyani,Moughlai");
restrnt.setAddress("Kolkata,E M Bypass");
restrnt.setOpenhours("10:00am-10:00pm");
results.add(restrnt);
restrnt=new Restaurent();
restrnt.setFoodJointname("Bhajohori Manna");
restrnt.setCuisine("Bengali,Chinese");
restrnt.setAddress("Kolkata,Esplanede");
restrnt.setOpenhours("10:00am-10:00pm");
results.add(restrnt);
restrnt=new Restaurent();
restrnt.setFoodJointname("Bar B Q");
restrnt.setCuisine("Bengali,Chinese,Thai");
restrnt.setAddress("Kolkata,Park Street");
restrnt.setOpenhours("10:00am-10:00pm");
results.add(restrnt);
return results;
}
public void makeAToast(String str) {
//yet to implement
Toast toast = Toast.makeText(this, str, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
我可以显示一个带有一堆文本视图的自定义列表视图作为它的项目,但是,我想在列表视图上获取餐厅 setOnItemClick 的名称。
例如,每当我点击“Bar B Q”、“calcutta Food Court”时,它只会显示“Bar B Q”、“calcutta Food Court”而不是其他信息。thnx提前。如果你需要任何东西,请随意。
“我的应用程序屏幕截图”