本文介绍了如何使用android中的listview项目设置带有操作栏的搜索图标,用于jellybean和更高版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
package com.krishna.upahara;
public class CateringList extends Activity
{
ItemVO details;
Bfs categoryDetails;
ArrayList<ItemVO> itemList;
ArrayList<String> itemsList;
String cat;
ArrayAdapter<String> arrayAdapter;
ListView lv;
private SharedPreferences sp;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.list_item_name);
itemList = new ArrayList<ItemVO>();
details = (ItemVO) ApplicationCache.getInstance().getValue("categoryNameDetails");
categoryDetails = (Bfs) ApplicationCache.getInstance().getValue("categoryTypeDetails");
itemList = categoryDetails.getCategoryNameDetails();
lv = (ListView) findViewById(R.id.list1);
arrayAdapter = new ArrayAdapter<String>(this,R.layout.listview_items,R.id.textView);
for (ItemVO mnvo : categoryDetails.getCategoryNameDetails())
{
Log.d("TestTag", "Name of custome care"+mnvo.getCategoryName());
arrayAdapter.add(mnvo.getCategoryName());
}
//binding adapter
lv.setAdapter(new MyAdapter(CateringList.this,R.id.textView,itemList));
sp = getSharedPreferences("aksp", Context.MODE_PRIVATE);
//store your data in a key/value form
String items = sp.getString("Items", null);
String[] itemsArray = null;
itemsList = new ArrayList<String>();
if(items == null || items.equalsIgnoreCase(""))
{
}
else
{
itemsArray = items.split("\\|");
for(String c : itemsArray)
{
itemsList.add(c);
}
}
Intent intentObject = getIntent();
cat = intentObject.getStringExtra("categorypos");
ItemListAdapter dataAdapter = new ItemListAdapter(this,R.layout.listview_items, itemList);
lv.setAdapter(dataAdapter);
Button myButton = (Button) findViewById(R.id.button1);
myButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String items = "";
int count = 0;
for(ItemVO c : itemList)
{
if(c.isSelected())
{
count++;
items =items+"\n"+ c.getItemdescription();
sp.edit().putString("items", items).commit();
}
}
if(count==0)
{
Toast.makeText(CateringList.this, "Please select at least one item", Toast.LENGTH_LONG).show();
return;
}
String catitems=cat +"\n "+"Items:" + items;
Intent iIntent = new Intent(CateringList.this,MyCart.class);
iIntent.putExtra("catitems", catitems);
startActivity(iIntent);
ApplicationCache.getInstance().clear();
itemsList.clear();
String[] countriesArray = items.split("\\|");
for(String c : countriesArray)
{
itemsList.add(c);
}
}
});
}
private class MyAdapter extends ArrayAdapter<ItemVO>
{
private Context context;
private ArrayList<ItemVO> list;
public MyAdapter (Context context, int textViewResourceId, ArrayList<ItemVO> list)
{
super(context, textViewResourceId, list);
this.context = context;
this.list = list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
// TODO Auto-generated method stub
{
LayoutInflater li = (LayoutInflater) getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = li.inflate(R.layout.listview_items,null);
TextView itemName = (TextView) convertView.findViewById(R.id.textView1);
itemName.setText(list.get(position).getItemdescription());
Log.d("TestTag", "Inside getView"+list.get(position).getItemdescription());
return convertView;
}
}
}
}
推荐答案
这篇关于如何使用android中的listview项目设置带有操作栏的搜索图标,用于jellybean和更高版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!