how to update listview in Popup window in Android - android

I have one TextView with title All Post.I'm displaying the popup window click on TextView and populate list view with two items in popup window.And trying to implement this - whenever click on list view item that item will be display in TextView and previous TextView title All Post will be add in listview in the place of clickable item.But my listview is not update on dismiss the popup window.
Here is my code of popup window.
String[] values = new String[] { "All Post", "My Post", "R-Post"};
ArrayList<String> filter_PostType = new ArrayList<String>();
str_LastSelectionValue = sharedPreferences.getString("filter_post_title", "");
if(str_LastSelectionValue.equals("NoVal"))
{
editor.putString("filter_post_title","All Post");
editor.commit();
}
else
{
str_LastSelectionValue = sharedPreferences.getString("filter_post_title", "");
}
textSearch.setText(str_LastSelectionValue);
Log.e("", " textSearch.getText().toString().trim() = " +
textSearch.getText().toString().trim());
textSearch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
popup_searchview = new PopupWindow(CustomActionActivity.this);
View layout = getLayoutInflater().inflate(R.layout.allpostsearch_popup, null);
popup_searchview.setContentView(layout);
popup_searchview.setHeight(220);
popup_searchview.setWidth(250);
popup_searchview.setOutsideTouchable(true);
popup_searchview.setFocusable(true);
popup_searchview.setBackgroundDrawable(new BitmapDrawable());
popup_searchview.showAsDropDown(v);
filter_list = (ListView) layout.findViewById(R.id.filter_ListView);
arr = new ArrayList<String>(Arrays.asList(values));
filter_PostType.clear();
for (int i = 0; i < arr.size(); i++) {
String str_PostType = arr.get(i);
if (!str_PostType.equals(str_LastSelectionValue)) {
filter_PostType.add(str_PostType);
}
}
filterPost_adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.filter_popup_list_item, R.id.text_filter_title, filter_PostType);
filter_list.setAdapter(filterPost_adapter);
filter_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedFromList = (filter_list.getItemAtPosition(position).toString());
editor.putString("filter_post_title", selectedFromList);
editor.commit();
textSearch.setText(selectedFromList);
popup_searchview.dismiss();
removeItemFromList(position);
filterPost_adapter.notifyDataSetChanged();
arr = new ArrayList<String>(Arrays.asList(values));
filter_PostType.clear();
for (int i = 0; i < arr.size(); i++)
{
String str_PostType = arr.get(i);
if (!str_PostType.equals(textSearch.getText().toString().trim()))
{
filter_PostType.add(str_PostType);
int filterSize = filter_PostType.size();
Log.e(" UnMatched ", " In ListItem Click filterSize = " + filterSize);
}
}
filterPost_adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.filter_popup_list_item, R.id.text_filter_title, filter_PostType);
filter_list.setAdapter(filterPost_adapter);
}
});
}
});

Use something like this:
String[] values = new String[] { "All Post", "My Post", "R-Post"};
ArrayList<String> filter_PostType = new ArrayList<String>();
str_LastSelectionValue = sharedPreferences.getString("filter_post_title", "NoVal");
if(str_LastSelectionValue.equals("NoVal"))
{
editor.putString("filter_post_title","All Post");
editor.commit();
}
else
{
str_LastSelectionValue = sharedPreferences.getString("filter_post_title", "");
}
textSearch.setText(str_LastSelectionValue);
Log.e("", " textSearch.getText().toString().trim() = " +
textSearch.getText().toString().trim());
textSearch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
str_LastSelectionValue = sharedPreferences.getString("filter_post_title", "");
popup_searchview = new PopupWindow(CustomActionActivity.this);
View layout = getLayoutInflater().inflate(R.layout.allpostsearch_popup, null);
popup_searchview.setContentView(layout);
popup_searchview.setHeight(220);
popup_searchview.setWidth(250);
popup_searchview.setOutsideTouchable(true);
popup_searchview.setFocusable(true);
popup_searchview.setBackgroundDrawable(new BitmapDrawable());
popup_searchview.showAsDropDown(v);
filter_list = (ListView) layout.findViewById(R.id.filter_ListView);
if(!filter_PostType.isEmpty())
filter_PostType.clear();
for (int i = 0; i < values.length; i++) {
if (!values[i].equals(str_LastSelectionValue)) {
filter_PostType.add(values[i]);
}
}
filterPost_adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.filter_popup_list_item, R.id.text_filter_title, filter_PostType);
filter_list.setAdapter(filterPost_adapter);
filter_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedFromList = (filter_list.getItemAtPosition(position).toString());
editor.putString("filter_post_title", selectedFromList);
editor.commit();
str_LastSelectionValue=selectedFromList;
textSearch.setText(selectedFromList);
popup_searchview.dismiss();
}
});
}
});
}
You don't need to change your adapter after user selects something because the next time user clicks the textview, you are making a new popup window with a new adapter.
If there is anything you don't understand, leave a comment.
Hope this helps :)

Related

Trying to set the marker on the current position gives me nullpointer exception

I have done the following things in my program:
I am generating some Buttons programmatically in my MenuItemsActivity class. I have a Listview in the xml of the MenuItemsActivity class.
When I click on the button the appropriate contents get loaded in the Listview. I just refresh the activity i.e I am using the same Listview to load different contents based on the button which is clicked.
I want to do the following:
When the Button is clicked I want to change the background of the button to 'blue_tab` and maintain that same color when the same activity reloads. Can anyone guide me step by step what to do, as I am a newbie to Android.
i = getIntent();
String Salad=i.getStringExtra("Salad");
String cat_name_from_fragment=i.getStringExtra("category name");
final ListView salad_list = (ListView) findViewById(R.id.salads);
category = new ArrayList<HashMap<String, String>>();
items = new ArrayList<HashMap<String, String>>();
db = new DbHelper(MenuItemsActivity.this);
category.clear();
if (i.getStringExtra("category name") != null) {
String getcategory = i.getStringExtra("category name").toString();
items = db.retrieve_item_details(getcategory);
Log.i("sub items", "" + items);
}
else if(cat_name_from_fragment!=null)
{
items = db.retrieve_item_details(cat_name_from_fragment);
}
else
{
items = db.retrieve_item_details("Salads");
}
category = db.retrieve_category_name();
count = category.size();
Log.i("Sqlite database values", "" + count + " " + category);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
LinearLayout l1 = (LinearLayout) findViewById(R.id.tableRow1);
int i = 0;
for (HashMap<String, String> map : category)
for (Entry<String, String> mapEntry : map.entrySet()) {
String key = mapEntry.getKey();
String value = mapEntry.getValue();
TextView tv2 = new TextView(this);
tv2.setLayoutParams(new LinearLayout.LayoutParams(40, 90));
Log.i("map", "" + value);
final Button tv1 = new Button(this);
tv1.setId(i);
tv1.setText(value);
tv1.setTextSize(35);
tv1.setTextColor(Color.parseColor("#1569C7"));
tv1.setGravity(Gravity.CENTER);
tv1.setBackgroundDrawable(getResources().getDrawable(R.drawable.popup));
tv1.setLayoutParams(new LinearLayout.LayoutParams(300,90));
tv1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
String text = tv1.getText().toString();
Log.e("text message", "" + text);
tv1.setBackgroundDrawable(getResources().getDrawable(R.drawable.blue_tab));
Toast.makeText(MenuItemsActivity.this, "clicked", 1000)
.show();
Intent i = new Intent(MenuItemsActivity.this,
MenuItemsActivity.class);
i.putExtra("category name", "" + text);
finish();
startActivity(i);
}
});
/*TextView tv2 = new TextView(this);
tv2.setText(" ");
tv2.setTextSize(10);
tv2.setGravity(Gravity.CENTER);*/
l1.addView(tv1);
l1.addView(tv2);
i++;
Log.e("i count ", "" + i);
}
final int imageArra[] = { R.drawable.leftbar_logo ,R.drawable.leftbar_logo};
ListAdapter k = new SimpleAdapter(MenuItemsActivity.this, items,
R.layout.menulist, new String[] { "Item_Name", "Desc",
"Currency", "Price","url","veggie","cat" }, new int[] { R.id.cat_name,
R.id.textView1, R.id.textView2, R.id.textView3,R.id.url,R.id.veggie,R.id.Category}) {
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final View v = super.getView(position, convertView, parent);
final ImageView im=(ImageView)v.findViewById(R.id.imageView1);
TextView url=(TextView)v.findViewById(R.id.url);
TextView veg=(TextView)v.findViewById(R.id.veggie);
String vegg=veg.getText().toString();
ImageView imagevegs=(ImageView)v.findViewById(R.id.veggies);
Log.i("veggie",""+vegg);
if(vegg.compareToIgnoreCase("Veg")==0)
{
imagevegs.setImageResource(R.drawable.veg);
imagevegs.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
}
else
{imagevegs.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imagevegs.setImageResource(R.drawable.non);
}
final String urls="http://166.62.17.208/"+url.getText().toString();
Log.i("urls",""+urls);
imageLoader.DisplayImage(urls,im);
//return super.getView(position, convertView, parent);
return v;
}
};
salad_list.setAdapter(k);
You can use PreferenceManager to save data and use it when the app is reloaded/restarted
sample:
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
String text = tv1.getText().toString();
Log.e("text message", "" + text);
if(PreferenceManager.getDefaultSharedPreferences(MenuItemsActivity.this).getString("button", "").length != 0)
tv1.setBackgroundDrawable(getResources().getDrawable(R.drawable.blue_tab));
else
{
Editor editor = PreferenceManager.getDefaultSharedPreferences(MenuItemsActivity.this).edit();
editor.putString("button", "1");
editor.commit();
tv1.setBackgroundDrawable(getResources().getDrawable(R.drawable.blue_tab));
}
Toast.makeText(MenuItemsActivity.this, "clicked", 1000)
.show();
Intent i = new Intent(MenuItemsActivity.this,
MenuItemsActivity.class);
i.putExtra("category name", "" + text);
finish();
startActivity(i);
}

How to refresh list View in android?

I am using .net web services. I am trying to get list in ListView. Right now it is showing me the first list, but when I am trying to get it again using the same method it is giving me a response in log but not displaying in list.
I have used mAdapter.notifyDataSetChanged(); in my Adapter but it's not working. Please help. thanks
My code:
Intent mIntent = getIntent();
mIntent.getStringExtra("folder_name");
Id = mIntent.getStringExtra("folder_ID");
mIntent.getStringExtra("item_parent");
User_ID = mIntent.getStringExtra("User_ID");
subfolderTreedata();
}
public void subfolderTreedata() {
try {
--------
--------
-------- //some code here...
SoapObject SubfolderResponse = (SoapObject)envelope.getResponse();
Log.i("SubFolders", SubfolderResponse.toString());
String File_Ext=" ";
subfoldersitem = new String[SubfolderResponse.getPropertyCount()];
System.out.println(subfoldersitem.length);
for(int i=0; i < SubfolderResponse.getPropertyCount(); i++) {
SoapObject SingleSubFolder = (SoapObject)SubfolderResponse.getProperty(i);
subfoldersitem[0] = SingleSubFolder.getProperty(1).toString();
subfoldersitem[1] = SingleSubFolder.getProperty(0).toString();
subfoldersitem[2] = SingleSubFolder.getProperty(3).toString();
if(KEY_SUBJECTTYPE.equalsIgnoreCase("Folder")) {
item = new FolderList(Folderimages[0], subfoldersitem[0], subfoldersitem[1], subfoldersitem[2]);
Subfolderdata.add(item);
} else{
StringTokenizer tokens = new StringTokenizer(Name, ".");
#SuppressWarnings("unused")
String first_string = tokens.nextToken();
File_Ext = tokens.nextToken();
if(File_Ext.equalsIgnoreCase("TIF")) {
item = new FolderList(TIFimages[0], subfoldersitem[0], subfoldersitem[1], subfoldersitem[2]);
Subfolderdata.add(item);
} else {
item = new FolderList(noImage[0], subfoldersitem[0], subfoldersitem[1], subfoldersitem[2]);
Subfolderdata.add(item); }
}
}
subfolderslistview = (ListView)findViewById(R.id.subfolderslistview);
mAdapter = new LazyAdapter(this, R.layout.jpg_row, Subfolderdata);
subfolderslistview.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
subfolderslistview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
LazyAdapter ca = (LazyAdapter)parent.getAdapter();
FolderList item_name = (FolderList)ca.getItem(position);
FolderList DocumentID = (FolderList)ca.getItem(position);
FolderList type = (FolderList)ca.getItem(position);
Intent mIntent = new Intent();
mIntent.putExtra("item_name", item_name.folder_name);
mIntent.putExtra("item_id", DocumentID.ID);
mIntent.putExtra("item_type", type.type);
mIntent.getStringExtra("item_name");
String Type = mIntent.getStringExtra("item_type");
Log.i("Type", Type);
if(Type.equalsIgnoreCase("Folder")){
Id = mIntent.getStringExtra("item_id");
mAdapter.notifyDataSetChanged();
subfolderTreedata();
} else {
Intent i = new Intent(getApplicationContext(), Display_image.class);
i.putExtra("item_name", item_name.folder_name);
i.putExtra("ID", DocumentID.ID);
i.putExtra("item_type", type.type);
i.putExtra("User_ID",User_ID);
i.getStringExtra("item_name");
Id = i.getStringExtra("ID");
i.getStringExtra("item_type");
Log.i("id", Id);
startActivity(i);
}
}
});
public void list() {
mAdapter = new LazyAdapter(this, R.layout.jpg_row, Subfolderdata);
subfolderslistview.setAdapter(mAdapter);
}
Use like this list();.
Call this method from Where do you want.

Custom List item change background in Android

Hi I am using custom listview and my list item contains checkbox. When updating the listview with the existing values the background is changed, so it is working fine.But when i clicks the check button, at that time the background will not changing after loading some where again then the background is changed . My question is at the time of check the item the background need to change immediately.
This is my adapter class.
public class GuestListAdapter extends BaseAdapter implements OnClickListener {
private String strExe;
AlertDialog.Builder builder;
Context context;
private ArrayList<String> arrayListFirstName;
private ArrayList<String> arrayListLastName;
private ArrayList<String> arrayListGuests;
private ArrayList<String> arrayCustomOne;
private ArrayList<String> arTempId;
private ArrayList<Boolean> chickinlist;
public static ArrayList<Integer> arrCheckedItems;
public static ArrayList<Integer> arrUnCheckedItems;
Button btnInfo;
private SQLiteAdapter mySqliteAdapter;
private GuestListScreen myGuestList;
private RelativeLayout views;
// private AlertDialog alertDialog = null;
private ArrayList<Boolean> checks = new ArrayList<Boolean>();
public GuestListAdapter(Context mcontext, ArrayList<String> arrListFN,
ArrayList<String> arrListLN, ArrayList<String> arrListGuest,
ArrayList<String> arrTiketID, ArrayList<String> arrCustOne,
ArrayList<Boolean> chicklist) {
clearAdapter();
arrayListFirstName = new ArrayList<String>();
arrayListLastName = new ArrayList<String>();
arrayListGuests = new ArrayList<String>();
arrayCustomOne = new ArrayList<String>();
arTempId = new ArrayList<String>();
chickinlist = new ArrayList<Boolean>();
arrCheckedItems = new ArrayList<Integer>();
arrUnCheckedItems = new ArrayList<Integer>();
arrayListFirstName = arrListFN;
arrayListLastName = arrListLN;
arrayListGuests = arrListGuest;
arrayCustomOne = arrCustOne;
arTempId = arrTiketID;
chickinlist = chicklist;
context = mcontext;
mySqliteAdapter = new SQLiteAdapter(context);
for (int i = 0; i < arrayListFirstName.size(); i++) {
checks.add(i, false);
}
}
#Override
public int getCount() {
// TODO Auto-generated method stub
Log.d("", "getCount" + arrayListFirstName.size());
return arrayListFirstName.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
Log.d("", "getItem" + arrayListFirstName.size());
return arrayListFirstName.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int position, View view, ViewGroup parent) {
final int pos = position;
views = null;
LayoutInflater layoutInflator = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
views = (RelativeLayout) layoutInflator.inflate(
R.layout.guest_list_item, null);
final CheckBox chk = (CheckBox) views.getChildAt(0);
// Log.d("", "CheckBox Pos "+position);
chk.setId(position);
TextView txtView = (TextView) views.getChildAt(1);
TextView txtView2 = (TextView) views.getChildAt(2);
TextView txtView3 = (TextView) views.getChildAt(3);
final TextView txtView4 = (TextView) views.getChildAt(4);
TextView txtView5 = (TextView) views.getChildAt(6);
txtView5.setId(position);
// Log.d("", "Button Pos "+position);
txtView4.setId(position);
txtView4.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, InfoScreen.class);
intent.putExtra("IDVALUE",arTempId.get(txtView4.getId()) );
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
context.startActivity(intent);
// System.out.println(v + "##########" + " " + v.getId());
// System.out.println(v + "##########" + " " + arTempId.get(txtView4.getId()));
// System.out.println(v + "##########" + " " + chickinlist.get(txtView4.getId()));
}
});
Log.e("", "****************************************************** " );
// Log.v("", "Adapter arr pos " + pos);
// Log.v("", "Adapter arr position " + position);
Log.v("", "Adapter arr size " + arrayListFirstName.size());
Log.v("", "Passsing arr size " + chickinlist.size());
for (int dd = 0; dd < arrayListFirstName.size(); dd++) {
if (position == dd) {
// Log.d("", "Passsing arr size " + chickinlist.size());
Boolean result = chickinlist.get(position);
// Log.d("", "After " + result);
if (result == true) {
chk.setChecked(true);
arrCheckedItems.add(position);
views.setBackgroundResource(R.drawable.list_item_checked);
} else {
chk.setChecked(false);
arrUnCheckedItems.add(position);
views.setBackgroundResource(R.drawable.list_item_unchecked);
}
txtView.setText(arrayListFirstName.get(position));
txtView2.setText(arrayListLastName.get(position));
txtView3.setText("(" + arrayListGuests.get(position) + ")");
if(arrayCustomOne.get(position).equalsIgnoreCase("0")||arrayCustomOne.get(position).equalsIgnoreCase(null)||arrayCustomOne.get(position).equalsIgnoreCase(""))
{
txtView5.setText("");
}else
{
txtView5.setText(arrayCustomOne.get(position));
}
}
}
chk.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
strExe = "update ticket_details set checkin_status=1 where tempid="+arTempId.get(chk.getId());
// Log.d("Adapter", "Checked Temp Id "+arTempId.get(chk.getId()));
Log.d("", "Position "+chk.getId()+"tempid "+arTempId.get(chk.getId()));
if (isChecked) {
// views.setBackgroundResource(R.drawable.list_item_checked);
AlertDialog.Builder builder = new AlertDialog.Builder(
context);
builder.create();
builder.setMessage(arrayListFirstName.get(chk.getId())
+ " " + arrayListLastName.get(chk.getId())
+ " has been checked in.");
builder.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int which) {
// myGuestList = new GuestListScreen();
mySqliteAdapter.executeCheckQurey(strExe);
// myGuestList.ListUpdate();
dialog.dismiss();
}
}).show();
// Log.d("", "ID = " + buttonView.getId());
} else {
// views.setBackgroundResource(R.drawable.list_item_unchecked);
strExe = "update ticket_details set checkin_status=0 where tempid="+arTempId.get(chk.getId());
mySqliteAdapter.executeCheckQurey(strExe);
// Toast.makeText(context, "check release", Toast.LENGTH_SHORT)
// .show();
}
}
});
return views;
}
#Override
public void onClick(View view) {
// TODO Auto-generated method stub
Integer index = (Integer) view.getTag();
boolean state = checks.get(index.intValue());
checks.set(index.intValue(), !state);
}
// private void showADialog(int posit) {
//
// AlertDialog.Builder builder = new AlertDialog.Builder(
// context);
// builder.create();
// builder.setMessage("The clicked row is "
// + arrayListFirstName.get(posit));
// builder.setPositiveButton("Ok?", new DialogInterface.OnClickListener() {
//
// #Override
// public void onClick(DialogInterface dialog, int which) {
// dialog.dismiss();
// }
//
// }).show();
// }
public void clearAdapter() {
if (arrayListFirstName != null) {
arrayListFirstName.clear();
arrayListFirstName = null;
arrayListLastName.clear();
arrayListLastName = null;
arrayListGuests.clear();
arrayListGuests = null;
arrayCustomOne.clear();
arrayCustomOne = null;
arTempId.clear();
arTempId = null;
chickinlist.clear();
chickinlist = null;
arrCheckedItems.clear();
arrCheckedItems = null;
arrUnCheckedItems.clear();
arrUnCheckedItems = null;
}
}
}
I just want to change the background of the checked item immediatly without updating the list again.
I think you need to tell the BaseAdapter to refresh the data when your OnCheckedChanged Listener is called.
GuestListAdapter.this.notifyDataSetChanged()

Android - When we select checkbox , Spinner need to change

I have checkBox and Spinner. If the checkbox is checked, then spinner should call the database and get the values from there, otherwise default value.
My Problem is :
If CheckBox is checked, Spinner should be called. How to implement this?
My code is :
private HashMap<Integer,ReturnProduct> retrunTypes =new HashMap<Integer, ReturnProduct>();
checkBox1=(CheckBox)findViewById(R.id.checkBox1);
checkBox1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
rtnStatus =true;
retrunTypes = getReturnRason();
}else {
rtnStatus =false;
}
}
});
Spinner:
retrunTypes = getReturnRason();
ArrayList<String> returnTypeList = new ArrayList<String>();
for (Map.Entry<Integer, ReturnProduct> entry : retrunTypes.entrySet()) {
ReturnProduct myProduct = entry.getValue();
returnTypeList.add(myProduct.getDescription());
}
retuReason = (Spinner) findViewById(R.id.retuReason);
reTypeAdapter = new ArrayAdapter<String>(SalesActivityGroup.group.getApplicationContext(),android.R.layout.simple_spinner_item, returnTypeList);
reTypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
retuReason.setAdapter(reTypeAdapter);
retuReason.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,int arg2, long arg3) {
//selectedReType = parent.getSelectedItem().toString();
selectedReTypeId= arg2;
selectedReType = retrunTypes.get(selectedReTypeId).getReturnReason();
//ReturnProduct rProduct = findReturnType(selectedReType);
processingRequird = retrunTypes.get(selectedReTypeId).getProcessingRequired();
selectedReTypeCode = selectedReType;
selectedRetCategory = retrunTypes.get(selectedReTypeId).getReturnCategory();
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
private HashMap<Integer,ReturnProduct> getReturnRason(){
DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(this);
HashMap<Integer,ReturnProduct> returnType = new HashMap<Integer, ReturnProduct>();
try {
dbAdapter.openDataBase();
String query ="";
if(rtnStatus) {
query = "SELECT rs.ReturnReasonCode,rs.ReturnType,rs.Description,rt.ProcessingRequired,rt.ReturnCategory " +
" FROM WMReturnReason rs,WMReturnType rt" +
" WHERE rs.ReturnType =rt.ReturnType AND rs.BusinessUnit=? AND Status ='1' AND rt.ProcessingRequired ='1' ";
}else {
query = "SELECT rs.ReturnReasonCode,rs.ReturnType,rs.Description,rt.ProcessingRequired,rt.ReturnCategory " +
" FROM WMReturnReason rs,WMReturnType rt" +
" WHERE rs.ReturnType =rt.ReturnType AND rs.BusinessUnit=? AND Status ='1' ";
}
String[] d = new String[]{strBusinessUnit};
ArrayList<?> stringList = dbAdapter.selectRecordsFromDBList(query, d);
dbAdapter.close();
//System.out.println("===getReturnType=="+stringList.size());
if(stringList.size() > 0){
for (int i = 0; i < stringList.size(); i++) {
ArrayList<?> arrayList = (ArrayList<?>) stringList.get(i);
ArrayList<?> list = arrayList;
ReturnProduct returnProduct = new ReturnProduct();
returnProduct.setReturnReason((String) list.get(0));
returnProduct.setReturnType((String) list.get(1));
returnProduct.setDescription((String) list.get(2));
returnProduct.setProcessingRequired((String) list.get(3));
returnProduct.setReturnCategory((String) list.get(4));
returnType.put(i, returnProduct);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return returnType;
}
You can use spinner.setSelection(pos) inside the setOnCheckedChangeListener. I can see that you have rolled out your own method to get the value from the database. Now based on the value returned just make the selection of your spinner.

How to get tablerow id dynamically in android?

Hello, my old code is working, but the problem is that when i am clicking tablerow it call another activty, but it not set that table row data but it setting last array data to that activity.
Means it set the last array value to next screen activity.
for ( j = 0; j < dataListfeture.size(); j++)
{
HashMap<String, String> hm = new HashMap<String, String>();
hm = dataListfeture.get(j);
final TableRow tblrow = new TableRow(MainScreen.this);
final View rowView = inflater.inflate(R.layout.featuredrow, null);
tblrow.setId(j);
tblrow.getId();
featuredName = (TextView) rowView.findViewById(R.id.xxName);
featuredDistance = (TextView) rowView.findViewById(R.id.xxDistance);
featuredVeneType = (TextView) rowView.findViewById(R.id.xxVeneType);
featuredPhone = (TextView) rowView.findViewById(R.id.xxPhone);
featuredAddress = (TextView) rowView.findViewById(R.id.xxAddress);
Drawable image = ImageOperations(MainScreen.this, hm.get("url"), "image.jpg");
featuredImage = (ImageView) rowView.findViewById(R.id.xxdImage);
featuredImage.setImageDrawable(image);
featuredName.setText("" + hm.get("name"));
featuredDistance.setText("" + hm.get("distance") + " mi");
featuredVeneType.setText("" + hm.get("venuetype"));
featuredPhone.setText("" + hm.get("phonenumber"));
featuredAddress.setText("" + hm.get("address"));
mapnamelist = hm.get("name");
mapvenuelist = hm.get("venuetype");
mapothervenuelist = hm.get("othervenuetype");
mapaddresslist= hm.get("address");
mapcitylist= hm.get("city");
mapstatelist= hm.get("state");
tblrow.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
final ProgressDialog progDailog = ProgressDialog.show(MainScreen.this, null, "Loading ....", true);
final Handler handler = new Handler()
{
public void handleMessage(Message msg)
{
System.out.println("search");
Intent myIntent = new Intent(MainScreen.this, xxxxscreen.class);
startActivity(myIntent);
MainScreen.this.finish();
progDailog.dismiss();
}
};
new Thread()
{
public void run()
{
try
{
System.out.println();
handler.sendEmptyMessage(1);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}.start();
}
});
Create an int array of id say array_id[] and after setting id to table row add that id to array_id[] also like
tblrow.setId(j);
array_id[j] = j;
And in onClick method do this:
for(int i = 0;i< array_id.length;i++)
{
TableRow tbl_row = (TableRow) findViewById(i);
if(v.getId() == array_id[i])
{
/** Perform your Operations */
}
}

Categories

Resources