How to add dymnamically selected gridview items in listview - android

First activity : gridview, whenever u click on gridview item dialogBox is opened which contains spinner. Now, I want to display Selected Gridview item and selected spinner values in Second Activity contains Listview. When u click on secondtime the values are replaced in listview but not added.
Can anyone plz help me...........
MainActivity...
public class MainActivity extends Activity implements OnClickListener {
SharedPreferences SharedPrefs;
String sp_selected;
Spinner sp;
String s1;
String partname;
String partname1;
Button Parts_history;
Imageadapter image_adapter;
private static final String[] paths = { "Select Your Choice", "Type1",
"Type2", "Type3", "Type4" };
private static final int position = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.partsrepair);
image_adapter = new Imageadapter(this);
SharedPrefs = getSharedPreferences("Preference", MODE_PRIVATE);
GridView gridview = (GridView) findViewById(R.id.gridView1);
gridview.setAdapter(new Imageadapter(this));
Parts_history = (Button) findViewById(R.id.partshistory_button);
Parts_history.setOnClickListener((this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(final AdapterView<?> parent, View v,
int position, long id) {
SharedPreferences.Editor edit = SharedPrefs.edit();
// partname = parent.getItemAtPosition(position).toString();
partname1 = image_adapter.names[position].toString();
image_adapter.names[position].toString();
Toast.makeText(MainActivity.this, "you Selected:" + partname1,
Toast.LENGTH_SHORT).show();
// edit.putString("SelectPart", partname1);
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.repairtype_spinner);
dialog.setCancelable(true);
Spinner sp = (Spinner) dialog.findViewById(R.id.spinner_1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
MainActivity.this,
android.R.layout.simple_spinner_item,paths);
sp.setAdapter(adapter);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
if (position > 0) {
sp_selected = parent.getItemAtPosition(position)
.toString();
}
}
#Override
public void onNothingSelected(AdapterView<?>arg0) {
// TODO Auto-generated method stub
}
});
Button btnOk = (Button)dialog.findViewById(R.id.Button_sms_ok);
btnOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SharedPreferences.Editor edit = SharedPrefs.edit();
if ((sp_selected != null)
&& !sp_selected.equals("Select Your Choice")) { //
edit.putString("SelectType", sp_selected);
Toast.makeText(getApplicationContext(),
"You selected:" + sp_selected,
Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(),
"Thank You!", Toast.LENGTH_LONG).show();
dialog.dismiss();
} else {
Toast.makeText(MainActivity.this,
"plz Select your Choice",
Toast.LENGTH_SHORT).show();
}} });
dialog.show(); }});}
public void onClick(View v) {
switch (v.getId()) {
case R.id.partshistory_button:
Intent intent = new Intent(MainActivity.this, ListViewItems.class);
intent.putExtra("Part", partname1);
intent.putExtra("Type", sp_selected);
startActivity(intent);
finish();
}}}
listview.class
public class ListViewItems extends Activity {
ArrayList<String> part, type;
ListView list;
public ListViewItems() {
// TODO Auto-generated constructor stub
part = new ArrayList<String>();
type = new ArrayList<String>();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sms_summary);
Intent i = getIntent();
part.add(i.getStringExtra("Part"));
type.add(i.getStringExtra("Type"));
list = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getBaseContext(), R.layout.listview, type);
list.setAdapter(new CustomViewAdapter(ListViewItems.this));
adapter.notifyDataSetChanged();
}
public class CustomViewAdapter extends BaseAdapter {
Context context;
public CustomViewAdapter(Context context) {
// TODO Auto-generated constructor stub
this.context = context;
}
private class ViewHolder {
TextView text_part;
TextView text_type;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
// Log.d("hao",""+position);
LayoutInflater minflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = minflater.inflate(R.layout.listview, null);
holder = new ViewHolder();
holder.text_part = (TextView) convertView
.findViewById(R.id.textView1);
// Log.d("hao", ""+holder.text_desc);
holder.text_type = (TextView) convertView
.findViewById(R.id.textView2);
convertView.setTag(holder);
}
else
holder = (ViewHolder) convertView.getTag();
holder.text_type.setText(type.get(position));
holder.text_part.setText(part.get(position));
return convertView;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return part.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}}
Imageadapter.class
public class Imageadapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mlayoutinflater;
public Imageadapter(Context c) {
mContext = c;
mlayoutinflater = LayoutInflater.from(c);
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
class ViewHolder {
ImageView imageView;
TextView textView;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
ViewHolder childHolder;
if (convertView == null) {
// if it's not recycled, initialize some
convertView = mlayoutinflater.inflate(R.layout.partsnames, null);
childHolder = new ViewHolder();
childHolder.imageView = (ImageView) convertView
.findViewById(R.id.imageView1);
childHolder.textView = (TextView) convertView
.findViewById(R.id.textView1);
convertView.setTag(childHolder);
} else {
childHolder = (ViewHolder) convertView.getTag();
}
childHolder.imageView.setImageResource(mThumbIds[position]);
childHolder.textView.setText(names[position]);
return convertView;
}
public Integer[] mThumbIds = { R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher,R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher, };
public String[] names = { "First", "Second", "Third", "Fourth",
"Fifth", "Sixth", "Seventh" };
}

It seems the values are not really being overwritten. Each time the second activity is loaded new part and type ArrayLists are being created. In these new lists only the latest part and type are added (in the onCreate Function) which have travelled with the intent.
If you want the list to keep adding the part and type selected by the user you can maintain the lists on the MainActivity. So upon selection of each item and type add it to the list on the MainActivity and then pass it to the ListViewItems activity.
This way the list will always have all the items selected by you.
I must admit I am not 100% sure if I understood your question correctly. But I have tried to answer with as much as I did.
EDIT:
MainActivity:
public class MainActivity extends ActionBarActivity {
ArrayList<String> list;
int clickCount = 0;
static TextView textViewHelloWorld;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
list = new ArrayList<String>();
textViewHelloWorld = (TextView) findViewById(R.id.textViewHelloWorld);
Button buttonAddElements = (Button) findViewById(R.id.buttonAddElement);
buttonAddElements.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
clickCount = clickCount + 1;
textViewHelloWorld.setText("Click Count" + clickCount);
list.add("Click number " + clickCount);
}
});
Button buttonStartNewActivity = (Button) findViewById (R.id.buttonStartNewActivity);
buttonStartNewActivity.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bundle bundle = new Bundle();
bundle.putStringArrayList("list", list);
startActivity(new Intent(MainActivity.this, Main2Activity.class).putExtras(bundle));
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
Main2Activity: (ListView Activity):
public class Main2Activity extends ActionBarActivity {
ArrayList<String> list;
ListView listView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
list = getIntent().getStringArrayListExtra("list");
listView = (ListView) findViewById(R.id.listViewList);
String []dsf = new String[list.size()];
list.toArray(dsf);
listView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, dsf));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main2, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main2,
container, false);
return rootView;
}
}
}
EDIT2:
MainActivity.Java
public class MainActivity extends Activity implements OnClickListener {
SharedPreferences SharedPrefs;
String sp_selected;
Spinner sp;
String s1;
String partname;
String partname1;
Button Parts_history;
private ArrayList<String> parts;
private ArrayList<String> types;
Imageadapter image_adapter;
private static final String[] paths = { "Select Your Choice", "Type1",
"Type2", "Type3", "Type4" };
private static final int position = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.partsrepair);
image_adapter = new Imageadapter(this);
parts = new ArrayList<String>();
types = new ArrayList<String>();
SharedPrefs = getSharedPreferences("Preference", MODE_PRIVATE);
GridView gridview = (GridView) findViewById(R.id.gridView1);
gridview.setAdapter(new Imageadapter(this));
Parts_history = (Button) findViewById(R.id.partshistory_button);
Parts_history.setOnClickListener((this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(final AdapterView<?> parent, View v,
int position, long id) {
SharedPreferences.Editor edit = SharedPrefs.edit();
// partname = parent.getItemAtPosition(position).toString();
partname1 = image_adapter.names[position].toString();
parts.add(partname1);
image_adapter.names[position].toString();
Toast.makeText(MainActivity.this, "you Selected:" + partname1,
Toast.LENGTH_SHORT).show();
// edit.putString("SelectPart", partname1);
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.repairtype_spinner);
dialog.setCancelable(true);
Spinner sp = (Spinner) dialog.findViewById(R.id.spinner_1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
MainActivity.this,
android.R.layout.simple_spinner_item,paths);
sp.setAdapter(adapter);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
if (position > 0) {
sp_selected = parent.getItemAtPosition(position)
.toString();
types.add(sp_selected);
}
}
#Override
public void onNothingSelected(AdapterView<?>arg0) {
// TODO Auto-generated method stub
}
});
Button btnOk = (Button)dialog.findViewById(R.id.Button_sms_ok);
btnOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SharedPreferences.Editor edit = SharedPrefs.edit();
if ((sp_selected != null)
&& !sp_selected.equals("Select Your Choice")) { //
edit.putString("SelectType", sp_selected);
Toast.makeText(getApplicationContext(),
"You selected:" + sp_selected,
Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(),
"Thank You!", Toast.LENGTH_LONG).show();
dialog.dismiss();
} else {
Toast.makeText(MainActivity.this,
"plz Select your Choice",
Toast.LENGTH_SHORT).show();
}} });
dialog.show(); }});}
public void onClick(View v) {
switch (v.getId()) {
case R.id.partshistory_button:
Bundle bundle = new Bundle();
bundle.putStringArrayList("parts", parts);
bundle.putStringArrayList("type", types);
Intent intent = new Intent(MainActivity.this, ListViewItems.class);
intent.putExtra("Part", partname1);
intent.putExtra("Type", sp_selected);
intent.putExtra("bundle", bundle);
startActivity(intent);
finish();
}}}
ListView:
public class ListViewItems extends Activity {
ArrayList<String> part, type;
ListView list;
public ListViewItems() {
// TODO Auto-generated constructor stub
part = new ArrayList<String>();
type = new ArrayList<String>();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sms_summary);
Intent i = getIntent();
// part.add(i.getStringExtra("Part"));
// type.add(i.getStringExtra("Type"));
part = i.getExtras().getBundle("bundle").getStringArrayList("parts");
type = i.getExtras().getBundle("bundle").getStringArrayList("types");
list = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getBaseContext(), R.layout.listview, type);
list.setAdapter(new CustomViewAdapter(ListViewItems.this));
adapter.notifyDataSetChanged();
}
public class CustomViewAdapter extends BaseAdapter {
Context context;
public CustomViewAdapter(Context context) {
// TODO Auto-generated constructor stub
this.context = context;
}
private class ViewHolder {
TextView text_part;
TextView text_type;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
// Log.d("hao",""+position);
LayoutInflater minflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = minflater.inflate(R.layout.listview, null);
holder = new ViewHolder();
holder.text_part = (TextView) convertView
.findViewById(R.id.textView1);
// Log.d("hao", ""+holder.text_desc);
holder.text_type = (TextView) convertView
.findViewById(R.id.textView2);
convertView.setTag(holder);
}
else
holder = (ViewHolder) convertView.getTag();
holder.text_type.setText(type.get(position));
holder.text_part.setText(part.get(position));
return convertView;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return part.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}}

Related

ListView not showing right item after filtering

Its been a week since I'm stuck with this problem.
I developed an application with a listView and editText to make a search. When I make a search the new list is showed very well but when I click on the item it redirect me to the item of the inicial list.
I don't know what to do please help me. These are my codes.
-For the ReaderListAdapter :
public class ReaderListAdapter extends BaseAdapter {
ArrayList<Reader> listReader = new ArrayList<Reader>();
ArrayList<Reader> arrayList;
LayoutInflater layoutInflater;
Context context;
int lastPosition = -1;
// constructeur
public ReaderListAdapter(Context context, ArrayList<Reader> listReader) {
this.listReader = listReader;
this.context = context;
arrayList = new ArrayList<Reader> ();;
layoutInflater = LayoutInflater.from(this.context);
arrayList.addAll(listReader);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return listReader.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return listReader.get(position);
}
#Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
static class ViewHolder {
TextView nomView;
TextView priceView;
ImageView pictureView;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.reader_row, null);
holder = new ViewHolder();
// initialisation des vues
holder.nomView = (TextView) convertView.findViewById(R.id.name);
holder.priceView = (TextView) convertView.findViewById(R.id.price);
holder.pictureView = (ImageView) convertView.findViewById(R.id.picture);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
// affchier les données convenablement dans leurs positions
holder.nomView.setText(listReader.get(position).getName());
holder.priceView.setText(String.valueOf(listReader.get(position).getPrice()));
holder.pictureView.setBackgroundDrawable(listReader.get(position).getPicture());
// changer R.anim.ton_effet
Animation animation = AnimationUtils.loadAnimation(context,(position > lastPosition)
? R.anim.up_from_bottom: R.anim.up_from_bottom);
convertView.startAnimation(animation);
position=lastPosition;
return convertView;
}
// Filter Class
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
listReader.clear();
if(charText.length()==0){
listReader.addAll(arrayList);
}
else{
for (Reader c : arrayList) {
if (c.getName().toLowerCase(Locale.getDefault())
.contains(charText)) {
listReader.add(c);
}
}
}
notifyDataSetChanged();
}
}
-For the MainActivity:
public class MainActivity extends Activity {
String[] listNames = { "kooora","yahoo", "hespress"};
int[] listPrices = { 1, 2, 3 };
ArrayList<Reader> listReader = new ArrayList<Reader>();;
ArrayList<Reader> listReaderNew;
ListView lv;
EditText search;
ReaderListAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.listReader);
search = (EditText) findViewById(R.id.search);
Drawable[] listPictures = {getResources().getDrawable(R.drawable.a1),getResources().getDrawable(R.drawable.a2),getResources().getDrawable(R.drawable.a3)};
for (int i = 0; i < listPictures.length; i++) {
listReader.add(new Reader(i + 1, listNames[i], listPictures[i], listPrices[i]));
}
adapter=new ReaderListAdapter(getApplicationContext(), listReader);
lv.setAdapter(adapter);
//lv.setAdapter(new ReaderListAdapter(getApplicationContext(), listReader));
search.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
String text = search.getText().toString().toLowerCase(Locale.getDefault());
MainActivity.this.adapter.filter(text);
}});
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent intent=new Intent(MainActivity.this,WebActivity.class);
switch (position) {
case 0:
intent.setData(Uri.parse("http://www.kooora.com")) ;break;
case 1:
intent.setData(Uri.parse("http://www.yahoo.com")) ;break;
case 2:
intent.setData(Uri.parse("http://www.hespress.com")) ;break; }if (intent != null) {
startActivity(intent);
}}});}}
Please help me. Thanks in advance!
I think the code in onItemClick is causing this.
The problem:
searchTerm = "yahoo"
You filter yahoo and show the listitem for yahoo. Lets says its position in the list is 0. When the user clicks it, the onItemClick will be called and case 0: will be executed.
The correct logic should be,
Reader reader = parent.getAdapter().getItem(position);
String searchTerm = reader.getName(); // or whichever is the id for that listitem
if(searchTerm.contains("yahoo")) {
intent.setData(Uri.parse("http://www.yahoo.com"))
} // and so on

how to update listview contents between fragments through the main activity

I have three fragments, the second and the third one, have a listView in their respective layout.
initially, the listView of both "second and third Frament", is populated with the same items. i other words, initially the the listView of
the second fragment and the third one, contain the following where CB: is checkBox and IV: is ImageView and t is: textview, and SaveButton is a buton
t1........CB.......IV
t2........CB.......IV
t3........CB.......IV
t4........CB.......IV
t5........CB.......IV
t6........CB.......IV
SaveButton
what i am trying to do is, while i am in the second fragment and selected an item(s) from the listView "using the checkbox" and clicked "Save" button, then, that item i selected, should be deleted from the listView in the third Fragment.
to achieve this,in getview(), i checked if the the checkBox is checked from the the listView of the second fragment, and if it is checked, i add the checked items
to a list. as shown in getView():
Second Fragment:
private void setUpListView() {
// TODO Auto-generated method stub
this.topicsList = new ArrayList<String>();
for (int i = 0; i < this.topics.length; i++) {
this.topicsList.add(topics[i]);
}
this.adapter = new ListViewAdapter(getActivity(), this.topicsList, ECO_FRAG_ID);
this.listView.setAdapter(adapter);
}
Third Fragment:
private void setUpListView() {
// TODO Auto-generated method stub
this.topicsList = new ArrayList<String>();
for (int i = 0; i < this.topics.length; i++) {
this.topicsList.add(topics[i]);
}
this.adapter = new ListViewAdapter(getActivity(), this.topicsList, LOGGER_FRAG_ID);
this.listView.setAdapter(adapter);
}
BaseAdapter:
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater layoutinflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = layoutinflater.inflate(R.layout.list_items_layout, null);
}
if (this.checkedItemsList1 == null) {
this.checkedItemsList1 = new ArrayList<String>();
}
if (this.checkedItemsList2 == null) {
this.checkedItemsList2 = new ArrayList<String>();
}
final TextView tv = (TextView) convertView.findViewById(R.id.tvlist_topic);
final CheckBox cb = (CheckBox) convertView.findViewById(R.id.cbList_hook);
final ImageView iv = (ImageView) convertView.findViewById(R.id.ivList_delete);
tv.setText(this.topicsList.get(position));
if (cb.isChecked() && (this.id == 1) ) {
this.checkedItemsList1.add(this.topicsList.get(position));
this.setCheckedItemsList1(this.checkedItemsList1);
}
if (cb.isChecked() && (this.id == 2) ) {
this.checkedItemsList2.add(this.topicsList.get(position));
this.setCheckedItemsList2(this.checkedItemsList2);
}
iv.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (cb.isChecked())
cb.setChecked(false);
topicsList.remove(position);
notifyDataSetChanged();
}
});
return convertView;
}
And i created an interface, which is initialised in onAttach() and called when i click the savebuton in the secondFragment as folows:
private OnClickListener btnSaveListener = new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getActivity(), "Save to SQLite", Toast.LENGTH_SHORT).show();
Log.d(TAG, "size: " + adapter.getCheckedItemsList1().size());
iCSC.onCheckedStateChanged(adapter.checkedItemsList1, ECO_FRAG_ID);
}
};
this inerface, the mainActivity implements it, and in the implemntation of the interface, i pass the list f the checked items from the second Fragment to the third
Fragment through a public method in the third fragmet that updates the list and then assign the list to the adapter, as follows:
#Override
public void onCheckedStateChanged(ArrayList<String> list, int id) {
// TODO Auto-generated method stub
switch (id) {
case 1:
((Logger_Settings_Frag) this.fragList.get(2)).updateTopicList(list);
break;
case 2:
break;
}
}
**updateTopicList in the third fragment**
public void updateTopicList(ArrayList<String> list) {
for (String str : list) {
this.topicsList.remove(str);
}
this.adapter = new ListViewAdapter(getActivity(), this.topicsList, LOGGER_FRAG_ID);
this.listView.setAdapter(adapter);
}
updateTopicList in the third fragment
public void updateTopicList(ArrayList<String> list) {
for (String str : list) {
this.topicsList.remove(str);
}
this.adapter = new ListViewAdapter(getActivity(), this.topicsList, LOGGER_FRAG_ID);
this.listView.setAdapter(adapter);
}
when i run that code, in the saveButton listener of the second fragment, the log.d message displays that the size of the list that should contain the items that was checked, is zero size?!
please have a look at the code and let me know what i am missing?
try this: Its a sample Project OneActivity with two Fragments:
public ArrayList myBeansList_frgnt1;
public ArrayList myBeansList_frgnt2;
by clicking the save button iterate the myBeansList_frgnt1 and checking the condition that any item is selected or not. if item is selected i am adding that item to myBeansList_frgnt2 .showing in fragment2.
MainActivity:
public class MainActivity extends FragmentActivity {
private FragmentManager mFragmentManager;
private MyFragment1 myFragment1;
public ArrayList<MyBean> myBeansList_frgnt1;
public ArrayList<MyBean> myBeansList_frgnt2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mFragmentManager = getSupportFragmentManager();
myBeansList_frgnt1 = new ArrayList<MyBean>();
myBeansList_frgnt2 = new ArrayList<MyBean>();
}
#Override
protected void onResume() {
super.onResume();
myFragment1 = new MyFragment1();
FragmentTransaction mTransaction = mFragmentManager.beginTransaction();
mTransaction.replace(R.id.framid, myFragment1, "applock").commit();
}
}
MyBaseAdpter: maintaining the states in the MyBean object
#Override
public View getView(int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = LayoutInflater.from(mContext).inflate(R.layout.list_item, null);
holder.mTextView = (TextView) view.findViewById(R.id.textView1);
holder.mBox = (CheckBox) view.findViewById(R.id.checkBox1);
holder.mImageView = (ImageView) view.findViewById(R.id.imageView1);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
final MyBean mBean = mBeansList.get(position);
holder.mBox.setOnCheckedChangeListener(null);
holder.mBox.setChecked(mBean.isChecked());
holder.mBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
mBean.setChecked(true);
} else {
mBean.setChecked(false);
}
}
});
// setting text and image
holder.mTextView.setText(mBean.getmName());
holder.mImageView.setImageResource(mBean.getmImgId());
return view;
}
private class ViewHolder {
TextView mTextView;
CheckBox mBox;
ImageView mImageView;
}
Fragment1:
public class MyFragment1 extends Fragment {
private ListView mListView;
private MyBaseAdpter myBaseAdpter;
private Button mButton;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_layout, null);
mListView = (ListView) view.findViewById(R.id.listviewid);
mButton = (Button) view.findViewById(R.id.bttnid);
return view;
}
#Override
public void onResume() {
super.onResume();
final MainActivity mActivity = (MainActivity) getActivity();
myBaseAdpter = new MyBaseAdpter(mActivity.myBeansList_frgnt1, getActivity());
mListView.setAdapter(myBaseAdpter);
mButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
int size = mActivity.myBeansList_frgnt1.size();
for (int i = 0; i < size; i++) {
MyBean mMyBean = mActivity.myBeansList_frgnt1.get(i);
if (mMyBean.isChecked()) {
mActivity.myBeansList_frgnt2.add(mMyBean);
}
}
}
});
}
}
Fragment2:
public class MyFragment2 extends Fragment {
private ListView mListView;
private MyBaseAdpter myBaseAdpter;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_layout, null);
mListView = (ListView) view.findViewById(R.id.listviewid);
return view;
}
#Override
public void onResume() {
super.onResume();
MainActivity mActivity = (MainActivity) getActivity();
myBaseAdpter = new MyBaseAdpter(mActivity.myBeansList_frgnt2, getActivity());
mListView.setAdapter(myBaseAdpter);
}
}
MyBean:
public class MyBean {
private String mName;
private int mImgId;
private boolean isChecked;
public String getmName() {
return mName;
}
public void setmName(String mName) {
this.mName = mName;
}
public int getmImgId() {
return mImgId;
}
public void setmImgId(int mImgId) {
this.mImgId = mImgId;
}
public boolean isChecked() {
return isChecked;
}
public void setChecked(boolean isChecked) {
this.isChecked = isChecked;
}
public MyBean() {
super();
// TODO Auto-generated constructor stub
}
}

How to add selected spinner values dynamically in listview is in another activity

How to add selected spinner values dynamically in listview is in another activity.
when I have changed spinner value in second time,and open listview activity values are replaced in the listview but not added.
public class MainActivity extends Activity implements OnClickListener {
SharedPreferences SharedPrefs;
String sp_selected;
Spinner sp;
String s1;
String partname;
String partname1;
Button Parts_history;
Imageadapter image_adapter;
private static final String[] paths = { "Select Your Choice", "Type1",
"Type2", "Type3", "Type4" };
private static final int position = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.partsrepair);
image_adapter = new Imageadapter(this);
SharedPrefs = getSharedPreferences("Preference", MODE_PRIVATE);
GridView gridview = (GridView) findViewById(R.id.gridView1);
gridview.setAdapter(new Imageadapter(this));
Parts_history = (Button) findViewById(R.id.partshistory_button);
Parts_history.setOnClickListener((this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(final AdapterView<?> parent, View v,
int position, long id) {
SharedPreferences.Editor edit = SharedPrefs.edit();
// partname = parent.getItemAtPosition(position).toString();
partname1 = image_adapter.names[position].toString();
image_adapter.names[position].toString();
Toast.makeText(MainActivity.this, "you Selected:" + partname1,
Toast.LENGTH_SHORT).show();
// edit.putString("SelectPart", partname1);
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.repairtype_spinner);
dialog.setCancelable(true);
Spinner sp = (Spinner) dialog.findViewById(R.id.spinner_1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
MainActivity.this,
android.R.layout.simple_spinner_item, paths);
sp.setAdapter(adapter);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
if (position > 0) {
sp_selected = parent.getItemAtPosition(position)
.toString();
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
Button btnOk = (Button) dialog.findViewById(R.id.Button_sms_ok);
btnOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SharedPreferences.Editor edit = SharedPrefs.edit();
if ((sp_selected != null)
&& !sp_selected.equals("Select Your Choice")) { //
edit.putString("SelectType", sp_selected);
Toast.makeText(getApplicationContext(),
"You selected:" + sp_selected,
Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(),
"Thank You!", Toast.LENGTH_LONG).show();
dialog.dismiss();
} else {
Toast.makeText(MainActivity.this,
"plz Select your Choice",
Toast.LENGTH_SHORT).show();
}
}
});
dialog.show();
}
});
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.partshistory_button:
Intent intent = new Intent(MainActivity.this, ListViewItems.class);
intent.putExtra("Part", partname1);
intent.putExtra("Type", sp_selected);
startActivity(intent);
finish();
}
}
}
listviewitems.class:
public class ListViewItems extends Activity {
ArrayList<String> part, type;
ListView list;
public ListViewItems() {
// TODO Auto-generated constructor stub
part = new ArrayList<String>();
type = new ArrayList<String>();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sms_summary);
Intent i = getIntent();
part.add(i.getStringExtra("Part"));
type.add(i.getStringExtra("Type"));
list = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getBaseContext(), R.layout.listview, type);
list.setAdapter(new CustomViewAdapter(ListViewItems.this));
adapter.notifyDataSetChanged();
}
public class CustomViewAdapter extends BaseAdapter {
Context context;
public CustomViewAdapter(Context context) {
// TODO Auto-generated constructor stub
this.context = context;
}
private class ViewHolder {
TextView text_part;
TextView text_type;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
// Log.d("hao",""+position);
LayoutInflater minflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = minflater.inflate(R.layout.listview, null);
holder = new ViewHolder();
holder.text_part = (TextView) convertView
.findViewById(R.id.textView1);
// Log.d("hao", ""+holder.text_desc);
holder.text_type = (TextView) convertView
.findViewById(R.id.textView2);
convertView.setTag(holder);
}
else
holder = (ViewHolder) convertView.getTag();
holder.text_type.setText(type.get(position));
holder.text_part.setText(part.get(position));
return convertView;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return part.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}
}

Progress dialog not showing in button click event in listview

I have a button in each list item of list view. In that button click event i have some codes to run. In click event im showing the progress dialog before the code runs. but its not getting shown. After all the codes in click event completes in the end progress dialog gets shown. Plz help me.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
TheListViewM = (ListView) findViewById(R.id.lvItems);
ImageAdapter anImageAdapterM =new ImageAdapter(this);
TheListViewM.setAdapter(anImageAdapterM);
}
public class ImageAdapter extends BaseAdapter {
private Context mContextL;
public ImageAdapter(Context contextP) {
mContextL = contextP;
}
public int getCount() {
return ItemList.GetLength();
}
public Object getItem(int PositionP) {
return ItemList.GetObject(PositionP);
}
public long getItemId(int PositionP) {
return PositionP;
}
public View getView(final int PositionP, View ConvertViewP, ViewGroup ParentP) {
if (ConvertViewP == null) {
LayoutInflater inflater = (LayoutInflater) mContextL.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ConvertViewP = inflater.inflate(R.layout.add_cart_row_layout, ParentP, false);
}
TextView textView1 = (TextView) ConvertViewP.findViewById(R.id.tvName);
textView1.setText("asdfg");
final Spinner spQuantity = (Spinner) ConvertViewP.findViewById(R.id.spQuantity);
spQuantity.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> Parent, View view,
int pos, long id) {
ProgressDialog aProgressDialogL = new ProgressDialog(mContextL);
aProgressDialogL.setMessage("Loading...");
aProgressDialogL.show();
//Processiing codes
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
ArrayAdapter<String> QuantityAdapter1 = new ArrayAdapter<String>(mContextL,android.R.layout.simple_spinner_item, QuantityList);
QuantityAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spQuantity.setAdapter(QuantityAdapter1);
Button btn1 = (Button) ConvertViewP.findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ProgressDialog aProgressDialogL = new ProgressDialog(activity1.this);
aProgressDialogL.setMessage("Loading...");
aProgressDialogL.show(); }
});
return ConvertViewP;
}
Try this one.
public class ImageAdapter extends BaseAdapter {
private Context mContextL;
public ImageAdapter(Context contextP) {
mContextL = contextP;
}
public int getCount() {
return ItemList.GetLength();
}
public Object getItem(int PositionP) {
return ItemList.GetObject(PositionP);
}
public long getItemId(int PositionP) {
return PositionP;
}
class ViewHolder {
Button btn1;
TextView textView1;
Spinner spQuantity;
}
public View getView(final int PositionP, View ConvertViewP, ViewGroup ParentP) {
ViewHolder holder;
if (ConvertViewP == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) mContextL.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ConvertViewP = inflater.inflate(R.layout.add_cart_row_layout, ParentP, false);
holder.textView1 = (TextView) ConvertViewP.findViewById(R.id.tvName);
holder.spQuantity = (Spinner) ConvertViewP.findViewById(R.id.spQuantity);
holder.btn1 = (Button) ConvertViewP.findViewById(R.id.btn1);
ConvertViewP.setTag(holder);
}
else{
holder = (ViewHolder) ConvertViewP.getTag();
}
holder.textView1.setText("asdfg");
holder.spQuantity.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> Parent, View view,
int pos, long id) {
ProgressDialog aProgressDialogL = new ProgressDialog(mContextL);
aProgressDialogL.setMessage("Loading...");
aProgressDialogL.show();
//Processiing codes
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
ArrayAdapter<String> QuantityAdapter1 = new ArrayAdapter<String>(mContextL,android.R.layout.simple_spinner_item, QuantityList);
QuantityAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.spQuantity.setAdapter(QuantityAdapter1);
holder.btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ProgressDialog aProgressDialogL = new ProgressDialog(activity1.this);
aProgressDialogL.setMessage("Loading...");
aProgressDialogL.show(); }
});
return ConvertViewP;
}
}

How to add a different icon in slidemenu listview

I am using slidemenu example from github and it's showing slide menu only with text and header but I need to add different icon with it. I am trying to use a custom adapter but it's not working...
slidemenu.java:
public class SlideMenu implements SlideMenuAnimationContainer.Listener {
public final static String[] slideMenuOptions = { "Recent Update", "Notification", "Wardrobe" };
public final static String TAG = "SlideMenu";
protected static final String TextView = null;
Intent intent;
private Context context;
private SlideMenuAnimationContainer slideMenuAnimationContainer;
public SlideMenu( Context context, SlideMenuAnimationContainer mainAnimationLayout){
this.context = context;
this.slideMenuAnimationContainer = mainAnimationLayout;
}
public void init(){
final Activity activity = (Activity) context;
//Set Content's show menu button's action
ImageView showMenuButton = (ImageView) activity.findViewById( R.id.content_button);
showMenuButton.setOnClickListener( new OnClickListener(){
#Override
public void onClick( View v){
slideMenuAnimationContainer.toggleSlideMenu();
}
});
//Contruct the SlideMenu items here, you can replace this ArrayAdapter with your customr ArrayAdapter
List<SlideMenuItem> slideMenuList = new ArrayList<SlideMenuItem>();
slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Header, "Updates"));
slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Activity, "Recent Update"));
// slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Header, "Header 2"));
slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Activity, "Notification"));
slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Header, "Category"));
slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Activity, "Wardrobe"));
slideMenuList.add( new SlideMenuItem( SlideMenuItemType.Activity, "Gadgets"));
SlideMenuArrayAdapter slideMenuArrayAdaptar = new SlideMenuArrayAdapter( context, android.R.layout.simple_list_item_1, slideMenuList);
ListView menuListView = (ListView) activity.findViewById( R.id.slideMenuListView);
menuListView.setAdapter( slideMenuArrayAdaptar);
menuListView.setOnItemClickListener( new OnItemClickListener(){
#Override
public void onItemClick( AdapterView<?> parent, View view, int position, long id){
// Close sidebar
slideMenuAnimationContainer.closeSlideMenuAndActOnClick( parent, view, position, id);
}
});
//Implement your logic here within the execute() function when an item is clicked with in the SlideMenu
//Called after the SlideMenu collapses.
slideMenuAnimationContainer.setMenuItemSelectedAction( new MenuItemSelectedAction(){
#Override
public void execute( AdapterView<?> parent, View view, int position, long id){
//Only act when a ListViewItem with type Activity is clicked
TextView textView = (TextView)view.findViewById( R.id.MenuActivityListViewItem_text);
if( textView != null && textView.getId() == R.id.MenuActivityListViewItem_text){
//Start new activity
CharSequence selectedActivityName = textView.getText();
if( selectedActivityName.equals( "Recent Update")) {
intent = new Intent( activity, Activity1.class);
}
else if( selectedActivityName.equals( "Notification")) {
intent = new Intent( activity, Activity2.class);
}
else if( selectedActivityName.equals( "Wardrobe")) {
intent = new Intent( activity, Activity3.class);
}
else if( selectedActivityName.equals( "Gadgets")) {
intent = new Intent( activity, Gadgets_Activity.class);
}
intent =intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
activity.startActivity( intent);
}
}
});
}
//Callback of SlideMenuAnimationContainer.Listener to monitor status of SlideMenu
#Override
public void onSlideMenuOpened(){
Log.d( TAG, "opened");
}
//Callback of SlideMenuAnimationContainer.Listener to monitor status of SlideMenu
#Override
public void onSlideMenuClosed(){
Log.d( TAG, "closed");
}
//Callback of SlideMenuAnimationContainer.Listener to monitor status of SlideMenu
#Override
public boolean onContentTouchedWhenOpening(){
//The content area is touched when sidebar opening, close sidebar
Log.d( TAG, "going to close sidebar");
slideMenuAnimationContainer.closeSlideMenu();
return true;
}
}
and Adapter:
public class SlideMenuArrayAdapter extends ArrayAdapter<SlideMenuItem> {
private List<SlideMenuItem> slideMenuItemList;
public SlideMenuArrayAdapter( Context context, int textViewResourceId, List<SlideMenuItem> slideMenuItemList) {
super( context, textViewResourceId, slideMenuItemList);
this.slideMenuItemList = slideMenuItemList;
}
#Override
public View getView( int position, View view, ViewGroup parent) {
SlideMenuItem slideMenuItem = slideMenuItemList.get( position);
LayoutInflater layoutInflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if( slideMenuItem.getSlideMenuItemType() == SlideMenuItemType.Header){
view = layoutInflater.inflate( R.layout.menu_header_listview_item, null);
TextView textView = (TextView) view.findViewById( R.id.MenuListHeaderListViewItem_text);
textView.setText( slideMenuItem.getText());
}
else if( slideMenuItem.getSlideMenuItemType() == SlideMenuItemType.Activity){
view = layoutInflater.inflate( R.layout.menu_activity_listview_item, null);
TextView textView = (TextView) view.findViewById( R.id.MenuActivityListViewItem_text);
textView.setText( slideMenuItem.getText());
}
else{
view = null; //Left for operation
}
return view;
}
}
Try like this
ListView listView = (ListView) menu.findViewById(R.id.list);
ArrayList<String[]> datavalues=new ArrayList<String[]>();
String[] menuhome=new String[2];
menuhome[0]=""+R.drawable.home_sidebar;
menuhome[1]="Home";
datavalues.add(menuhome);
String[] menuprofile=new String[2];
menuprofile[0]=""+R.drawable.profile_sidebar;
menuprofile[1]="Profile";
datavalues.add(menuprofile);
String[] menusearch=new String[2];
menusearch[0]=""+R.drawable.search_sidebar;
menusearch[1]="Search";
datavalues.add(menusearch);
String[] menugallery=new String[2];
menugallery[0]=""+R.drawable.gallery_sidebar;
menugallery[1]="Gallery";
datavalues.add(menugallery);
String[] menulogout=new String[2];
menulogout[0]=""+R.drawable.logout_sidebar;
menulogout[1]="Logout";
datavalues.add(menulogout);
SlideMenuAdapter menuadapter=new SlideMenuAdapter(datavalues, this);
listView.setAdapter(menuadapter);
private class SlideMenuAdapter extends BaseAdapter{
ArrayList<String[]> data;
ActivityListing context;
public SlideMenuAdapter(ArrayList<String[]> datavalues,
ActivityListing contextobj) {
// TODO Auto-generated constructor stub
data=datavalues;
context=contextobj;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
#Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return data.get(arg0);
}
#Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
#Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
final int pos=arg0;
// This a new view we inflate the new layout
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View convertView = inflater.inflate(R.layout.menurow, null, false);
int drawable=Integer.parseInt(data.get(arg0)[0].trim());
Button btnOption=(Button) convertView.findViewById(R.id.btnoption);
btnOption.setCompoundDrawablesWithIntrinsicBounds(context.getResources().getDrawable(drawable), null, null, null);
btnOption.setText(data.get(arg0)[1].trim());
btnOption.setTextColor(Color.rgb(143, 7, 0));
btnOption.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
callOptions(data.get(pos));
}
});
return convertView;
}

Categories

Resources