Problems with the ViewBinder - android

I need to display a ListView with some images, and I'm using the following code:
dataText = (TextView)findViewById(R.id.data);
dataText.setText(camping.stringIn + " >> " + camping.stringOut);
l = name.length;
ArrayList<tipologia> tipologieList=new ArrayList<tipologia>();
tipologia[] tip = new tipologia[l];
for (int i = 0; i < l; i++)
{
int rand = new Random().nextInt(3);
availability[i] = String.format("%d", rand);
tip[i] = new tipologia(image[i]);
}
for(int i=0; i<tip.length; i++)
{
tipologieList.add(tip[i]);
}
ArrayList<HashMap<String, Object>> data=new ArrayList<HashMap<String,Object>>();
for(int i=0;i<tipologieList.size();i++){
tipologia t = tipologieList.get(i);
HashMap<String,Object> tipologieMap = new HashMap<String, Object>();
tipologieMap.put("image", t.getImm());
data.add(tipologieMap);
}
String[] from={"image"};
int[] to={R.id.personImage};
SimpleAdapterMod adapter=new SimpleAdapterMod(
getApplicationContext(),
data,
R.layout.tipologia,
from,
to);
adapter.setViewBinder(new ViewBinder() {
public boolean setViewValue(View view, Object data,
String textRepresentation) {
if(data instanceof String && view instanceof Immagine ){
((Immagine)view).loadFromURL((String)data);
}
return true;
}
else{
return false;
}
}
});
I have a problem: in the list there's space for 4 rows, and when I scroll down it happens that the image of the fifth row is the same of the image of the first row and the subsequent images are wrong too.
Can someone tell me why?

Thats because the first row's view is reused for the fifth row, as the first row is now no more visible. The problem is in your adapter class.
In getView() method, do not reuse convertview, instead return a new view everytime. This is not the recommended solution but to be used as last resort.

Related

find repeated values in an array and print them to list view in android

I am new in android and I am trying to get the duplicate values in an array list. I have searched over the internet but I got nothing.
My project has two array lists one is for numbers and the second one is for displaying them. And if the first array list contains a duplicate values, the second one will display all the values and the duplicate ones will be displayed with a stars to mark them as a duplicate values.
So I have tried the following code but I have got nothing. In this situation, array list contains [9,9,5,7].
The problem is I do not get what I need, here is my code.
Note that: arrayList object that contains the numbers, array object will display them.. So any help on this?
arrayList.add(Integer.valueOf(students.getSeatnum()));
array.add(students.getStuden_name() + ", Student " + students.getStudent_id() + ", Seat Num: " + students.getSeatnum());
Set<Integer> seenValues = new HashSet();
for(Integer value: arrayList) {
if(seenValues.contains(value)) {
array.add(students.getStuden_name() + ", Student " + students. getStudent_id() + ", Seat Num: " + students.getSeatnum()+ "****");
adapter = new ArrayAdapter<String>(StudentInfo.this, android.R.layout.simple_list_item_1, array);
listView.setAdapter(adapter);
} else {
adapter = new ArrayAdapter<String>(StudentInfo.this, android.R.layout.simple_list_item_1, array);
listView.setAdapter(adapter);
}
}
Create an Adapter which accepts arrayList you have created.
Assuming you are using ListView from your variable name convention.
public class MySimpleArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final List<String> values;
public MySimpleArrayAdapter(Context context, List<String> values) {
super(context, -1, values);
this.context = context;
this.values = values;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context. getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
textView.setText(values.get(position));
return rowView;
}
}
Your method will look like this
ArrayList<String> array = new ArrayList<>();
Map<Integer,Integer> seenValues = new HashMap<>();
int i=0;
for(int value : arrayList){
if(seenValues.containsKey(value)){
if(seenValues.get(value) !=-1){
array.set(seenValues.get(value), String.valueOf(value) + "*");
seenValues.put(value,-1);
}
array.add(String.valueOf(value)+"*");
}else{
array.add(String.valueOf(value));
seenValues.put(value,i);
}
i++;
}
MySimpleArrayAdapter adapter = new adapter(context,array);
setListAdapter(adapter);
You can do it this way:
public class Test {
List<Integer> digits ;
List<String> digitsWatch;
public Test() {
digits = Arrays.asList(9,9,9,5,7,3,3);
digitsWatch = new ArrayList<>(digits.size());
// copying your array
for (int i = 0; i < digits.size(); i++) {
digitsWatch.add(digits.get(i).toString());
}
//filtred values
boolean hasDublicaqtes = false;
for (int i = 0; i < digits.size() -1 ; i++) {
for (int j = i +1; j < digits.size() ; j++) {
if(digitsWatch.get(j).equals(digits.get(i).toString()) ) {
hasDublicaqtes = true;
String tmp = digitsWatch.get(i) + "*";
digitsWatch.set(j,tmp);
}
}
if(hasDublicaqtes) {
String tmp = digitsWatch.get(i) + "*";
digitsWatch.set(i,tmp);
}
hasDublicaqtes = false;
}
}
}
Maybe it's not an optimal way but it works!

ArrayAdapter views duplicating after scrolling list

I created a custom ArrayAdapter and inside the ArrayAdapter there's a LinearLayout that adds views via iteration. Now after showing the data that needs to be shown on a ListView all will be well until I scroll down or up the list, when a row undergoes recycling and binding the new view to display on the recycled row I get duplicates, however this duplicates have show no data(text) on the views. Here is the view ListView before scrolling
https://postimg.org/image/z36eqhacd/
and here is the ListView after scrolling
https://postimg.org/image/dzv28kj9t/
I've tried multiple methods but can't seem to get it to work.
public class SurveyAdapter extends ArrayAdapter<SurveyModel> {
public SurveyAdapter(Context context, ArrayList<SurveyModel> objects) {
super(context, R.layout.survey_card, objects);
}
#NonNull
#Override
public View getView(int position, View convertView, #Nullable ViewGroup parent) {
//Get the data item for this position
SurveyModel surveyModel = getItem(position);
//Construct the ViewHolder
ViewHolder viewHolder = new ViewHolder();
//Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
//If there's no view to re-use, inflate a new view for a row
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.survey_card, parent, false);
viewHolder.mContainer = (LinearLayout) convertView.findViewById(R.id.choice_container);
viewHolder.question = (TextView) convertView.findViewById(R.id.question);
//Cache the viewHolder object inside the new view
convertView.setTag(viewHolder);
} else {
//View is being recycled, retrieve the viewHolder object from tag
viewHolder = (ViewHolder) convertView.getTag();
}
assert surveyModel != null;
//Populate the data from the data object
String choices = surveyModel.getChoice();
//Scan each string separately
//Strings are separated with a comma ','
Scanner scanner = new Scanner(choices).useDelimiter(",\\s*");
//Create an array list to store each string separately
ArrayList<String> choiceList = new ArrayList<>();
//Get all strings from scanner separately
while (scanner.hasNext()) {
String choice = scanner.next(); //Get each string from scanner
choiceList.add(choice); //Store the string in an ArrayList(choiceList)
}
//Convert choiceList(ArrayList) to a StringArray(choiceArray)
String[] choiceArray = choiceList.toArray(new String[choiceList.size()]);
int choiceNum; //Will store number of choices to be displayed
if (choices.contains("Other,true") || choices.contains("Other,false")) {
//Set number or choices to the length(number of items) of the choiceList(ArrayList)
//Minus 1 to avoid showing "true" as an option
choiceNum = choiceArray.length - 1;
} else {
//Set number or choices to the length(number of items) of the array
choiceNum = choiceArray.length;
}
//Get number of choices from choiceNum
final int numOfChoices = choiceNum;
//Populate each choice string from choiceArray
for (int i = 0; i < numOfChoices; i++) {
//Create a new CheckBox for each choice
AppCompatCheckBox checkBox = new AppCompatCheckBox(getContext());
checkBox.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
//Add the CheckBox to its survey_view_list view(mContainer)
viewHolder.mContainer.addView(checkBox);
if (viewHolder.mContainer.getChildAt(i) instanceof AppCompatCheckBox) {
//Set each data item in the choiceArray on its own CheckBox according to position
((AppCompatCheckBox) viewHolder.mContainer.getChildAt(i)).setText(choiceArray[i]);
final ViewHolder finalViewHolder = viewHolder; //Get viewHolder for inner class access
final int checkBoxPosition = i; //Set position of the checked CheckBox
((AppCompatCheckBox) viewHolder.mContainer.getChildAt(i)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (checked) {
for (int i = 0; i < numOfChoices; i++) {
//Disable all CheckBoxes when a CheckBox is checked
finalViewHolder.mContainer.getChildAt(i).setEnabled(false);
//Re-enable the checked CheckBox only
finalViewHolder.mContainer.getChildAt(checkBoxPosition).setEnabled(true);
}
} else {
for (int i = 0; i < numOfChoices; i++) {
//Enable all CheckBoxes when the checked CheckBox is unchecked
finalViewHolder.mContainer.getChildAt(i).setEnabled(true);
}
}
}
});
}
}
//Populate the data from the data object via the viewHolder object into the view
viewHolder.question.setText(surveyModel.getQuestion());
//Return the completed view to render on screen
return convertView;
}
//View lookup cache
private static class ViewHolder {
LinearLayout mContainer;
TextView question;
}`
Here is the Object Model
public class SurveyModel {
private String question, choice;
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getChoice() {
return choice;
}
public void setChoice(String choice) {
this.choice = choice;
}
}
Here is the method from the Activity I attach the ArrayAdapter to a ListView
//Method to populate and display data populated from the database
private void populateAndDisplayData() {
//Construct ArrayList
ArrayList<SurveyModel> surveyModelArrayList = new ArrayList<>();
//Construct adapter
SurveyAdapter adapter = new SurveyAdapter(CreateFromScratch.this, surveyModelArrayList);
//Attach the adapter to the ListView
binding.list.setAdapter(adapter);
//Create a ListView
ListView listView = new ListView(CreateFromScratch.this);
//Get all the data from the database
Cursor allDataCursor = tempSurveyDatabase.fetchAllData();
//StringArray to hold the strings from the database
String[] from = new String[]{CustomSurveyDatabase.QUESTION, CustomSurveyDatabase.CHOICES};
//Views to display the string data from StringArray(from)
int[] to = new int[]{R.id.question, R.id.choices};
//Construct a SimpleCursorAdapter
SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(CreateFromScratch.this, R.layout.survey_card, allDataCursor, from, to);
// /Attach the adapter to the ListView
listView.setAdapter(simpleCursorAdapter);
//Construct StringBuilder
StringBuilder jsonBuilder = new StringBuilder();
//Strings to hold the item's data from the database
String question = null;
String choices = null;
//Proceed with collecting each item's data if the SimpleCursorAdapter is not empty
if (simpleCursorAdapter.getCount() > 0) {
//Get every item's id from the database
for (int i = 0; i < simpleCursorAdapter.getCount(); i++) {
//Get each item's database id
long itemId = listView.getAdapter().getItemId(i);
//Get each item from the database
try {
//Construct cursor to fetch an item's data from the database
Cursor cursor = tempSurveyDatabase.fetchItem(itemId);
question = tempSurveyDatabase.questionHolder;
choices = tempSurveyDatabase.choiceHolder;
} catch (SQLException e) {
Log.v(TAG, e.getMessage());
}
if (i == 0) {
jsonBuilder.append("{\"survey\": [").append("{\"question\":\"").append(question).append("\",");
jsonBuilder.append("\"choices\":\"").append(choices).append("\"},");
} else {
jsonBuilder.append("{\"question\":\"").append(question).append("\",");
jsonBuilder.append("\"choices\":\"").append(choices).append("\"},");
}
}
//Remove the last comma from the StringBuilder
jsonBuilder.deleteCharAt(jsonBuilder.length() - 1);
//Close JSON file scopes
jsonBuilder.append("]}");
//Save temporary survey file on the SDCARD
try {
//Delete existing temporary survey
if (TEMP_SURVEY.exists()) {
//noinspection ResultOfMethodCallIgnored
TEMP_SURVEY.delete();
}
FileWriter fileWriter = new FileWriter(TEMP_SURVEY);
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(String.valueOf(jsonBuilder));
bufferedWriter.close();
} catch (IOException e) {
Log.v(TAG, "Temp Survey JSON file failed to write.\nReason: " + e.getMessage());
}
//Check if the temporary survey file exists
if (TEMP_SURVEY.exists()) {
//Read the temporary survey file if it exists
new ReadFile(ReadFile.data, ReadFile.output, TEMP_SURVEY);
//Parse JSON string from StringBuilder
try {
JSONObject jsonObjectMain = new JSONObject(ReadFile.output);
JSONArray jsonArray = jsonObjectMain.getJSONArray(SurveyJSONKeys.ARRAY_KEY);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
SurveyModel surveyModel = new SurveyModel();
surveyModel.setQuestion(jsonObject.getString(SurveyJSONKeys.QUESTION_KEY));
surveyModel.setChoice(jsonObject.getString(SurveyJSONKeys.CHOICES_KEY));
surveyModelArrayList.add(surveyModel);
}
} catch (JSONException e) {
Log.v(TAG, "Unable to parse JSON file.\nReason: " + e.getMessage());
}
//Notify the adapter for changes in order to refresh views
adapter.notifyDataSetChanged();
}
}
}`
Since your item view is recycled every time, the container of your answers are just appended with more answers. You have 2 options:
Remove all child views in your container before populating with answers
Do not force a recycle by using getViewTypeCount() and getItemViewType(int).

Why does variables changes depending on android version?

I got ListView with simpleAdapter. If I click on some item in my List view it show me 2 diferent variables.
Some code:
// Listview Data
ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>(Invoice_numberArr.length);
Map<String, Object> m;
for(int i = 0; i<Invoice_numberArr.length; i++){
int str = Integer.parseInt(Invoice_numberArr[i]);
int str2 = Integer.parseInt(InvoiceNumberForDetails);
if(str == str2){
m = new HashMap<String, Object>();
m.put(ATT_INU, Invoice_numberArr[i]);
m.put(ATT_ANU, Article_numberArr[i]);
m.put(ATT_AMO, AmountArr[i]);
m.put(ATT_PRE, PriceArr[i]);
m.put(ATT_TPR, Total_priceArr[i]);
m.put(ATT_SDE, Sale_designationArr[i]);
data.add(m);
}
}
String[] from = {ATT_INU, ATT_ANU, ATT_AMO, ATT_PRE, ATT_TPR, ATT_SDE};
int[] till = {R.id.txtInvoice_number, R.id.txtArticle_number, R.id.txtAmount, R.id.txtPrice, R.id.txtTotalPrice, R.id.txtSale_designation};
//activities elements
invoices_list_details_view = (ListView)findViewById(R.id.invoices_list_details_view);
invoicesDetailsSAdapter = new SimpleAdapter(InvoicesDetails.this, data, R.layout.invoices_list_item_details_view, from , till);
invoices_list_details_view.setAdapter(invoicesDetailsSAdapter);
Utility Utility = new Utility();
Utility.setListViewHeightBasedOnChildren(invoices_list_details_view);
//if item clicked
invoices_list_details_view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String positions = parent.getAdapter().getItem(position).toString();
//int positions = parent.getAdapter().;
parent.getAdapter();
int indexPos = -1; // if doesnt exist
for (int i = 0; i < Invoice_numberArr.length; i++) {
if (positions.contains("article_numbers="+Article_numberArr[i]+", "+"sale_designations="+Sale_designationArr[i]+", "+"amounts="+AmountArr[i]+", "+"invoice_numbers=" + Invoice_numberArr[i]+", "+"prices="+PriceArr[i]+", "+"total_prices="+Total_priceArr[i])) {
indexPos = i;
break;
} else if (positions.contains("prices="+PriceArr[i]+", "+"article_numbers="+Article_numberArr[i]+", "+"amounts="+AmountArr[i]+", "+"sale_designations="+Sale_designationArr[i]+", "+"invoice_numbers=" + Invoice_numberArr[i]+", "+"total_prices="+Total_priceArr[i])){
indexPos = i;
break;
}
}
//some int to transfer it to position class
int integerr = indexPos;
Intent invoices_details_position = new Intent(InvoicesDetails.this, InvoicesDetailsPosition.class);
invoices_details_position.putExtra("saleDesignationForPosition", Sale_designationArr[indexPos]);
invoices_details_position.putExtra("articleNumberForPosition", Article_numberArr[indexPos]);
invoices_details_position.putExtra("sequenceNumberForPosition", Sequence_numberArr[indexPos]);
invoices_details_position.putExtra("amountForPosition", AmountArr[indexPos]);
invoices_details_position.putExtra("warehouseForPosition", WarehouseArr[indexPos]);
invoices_details_position.putExtra("containerDescriptionForPosition", Container_descriptionArr[indexPos]);
invoices_details_position.putExtra("priceForPosition", PriceArr[indexPos]);
invoices_details_position.putExtra("discountForPosition", DiscountArr[indexPos]);
invoices_details_position.putExtra("totalPriceForPosition", Total_priceArr[indexPos]);
startActivity(invoices_details_position);
}
});
So if clicked on my item from ListView under android 4.3 till 5.0 varible
String positions = parent.getAdapter().getItem(position).toString();
shows me
string " {prices=10.8, article_numbers=0736, amounts=1, sale_designations=Pfirsichlikör, invoice_numbers=1, total_prices=10.8} "
And if I clicked under Android version 5.1 its shows me
string " {article_numbers=0736, sale_designations=Pfirsichlikör, amounts=1, invoice_numbers=1, prices=10.8, total_prices=10.8} "
Because that I need to check it twice with that
for (int i = 0; i < Invoice_numberArr.length; i++) {
if (positions.contains("article_numbers="+Article_numberArr[i]+", "+"sale_designations="+Sale_designationArr[i]+", "+"amounts="+AmountArr[i]+", "+"invoice_numbers=" + Invoice_numberArr[i]+", "+"prices="+PriceArr[i]+", "+"total_prices="+Total_priceArr[i])) {
indexPos = i;
break;
} else if (positions.contains("prices="+PriceArr[i]+", "+"article_numbers="+Article_numberArr[i]+", "+"amounts="+AmountArr[i]+", "+"sale_designations="+Sale_designationArr[i]+", "+"invoice_numbers=" + Invoice_numberArr[i]+", "+"total_prices="+Total_priceArr[i])){
indexPos = i;
break;
}
}
So my question now why does it changes depending on Android version ?
Thx for help.
Thank #Mike M. LinkedHashMap s instead HashMap s works for all Android

How to get a part of a datastring from clicking a listview-item

I have a variable called current which holds the last clicked listview item data. The id of this data is to be used to query the db again for movies taht are similar.
The problem that current = id=17985, title=the matrix, year=1999 when all i need is the actual id-number. I have tried to use substring to only use the correct places of the string. This works for the matrix since its id is exactly 5 digits long, but as soon as i try to click movie with higher/lower amount of digits in its id of course it trips up.
String id = current.substring(4,9).trim().toString(); does not work for all movies.
Heres some code:
// search method: this is necessary cause this is the method thats first used and where the variable current is set. This is also the only method using three lines for getting data - id, title and year.
protected void search() {
data = new ArrayList<Map<String, String>>();
list = new ArrayList<String>();
EditText searchstring = (EditText) findViewById(R.id.searchstring);
String query = searchstring.getText().toString().replace(' ', '+');
String text;
text = searchquery(query);
try {
JSONObject res = new JSONObject(text);
JSONArray jsonArray = res.getJSONArray("movies");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
item = new HashMap<String, String>(2);
item.put("id",jsonObject.getString("id"));
item.put("title",jsonObject.getString("title"));
item.put("year", jsonObject.getString("year"));
data.add(item);
}
} catch (Exception e) {
e.printStackTrace();
}
aa = new SimpleAdapter(SearchTab.this, data,
R.layout.mylistview,
new String[] {"title", "year"},
new int[] {R.id.text1,
R.id.text2});
ListView lv = (ListView) findViewById(R.id.listView1);
lv.setAdapter(aa);
lv.setDividerHeight(5);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
Map<String, String> s = data.get((int) id);
current = s.toString();
}});
}
// similar method: this tries to build a list from the fetched data from "current"-string. As you can see i try to use 4,9 to only get right numbers, but this fails with others. Best would be to only to be ble to get the ID which I cant seem to do. The toast is just to see what is beeing fetched, much like a system out print.
protected void similar() {
data = new ArrayList<Map<String, String>>();
list = new ArrayList<String>();
String id = current.substring(4,9).trim().toString();
Toast.makeText(getApplicationContext(), id, Toast.LENGTH_SHORT).show();
String text;
text = similarquery(id);
try {
JSONObject res = new JSONObject(text);
JSONArray jsonArray = res.getJSONArray("movies");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
item = new HashMap<String, String>(2);
item.put("title",jsonObject.getString("title"));
item.put("year", jsonObject.getString("year"));
data.add(item);
}
} catch (Exception e) {
e.printStackTrace();
}
aa = new SimpleAdapter(SearchTab.this, data,
R.layout.mylistview2,
new String[] {"title", "year"},
new int[] {R.id.text1,
R.id.text2});
ListView lv = (ListView) findViewById(R.id.listView1);
lv.setAdapter(aa);
lv.setDividerHeight(5);
}
Use current.split(",")[0].split("=")[1]
edit - assuming of course that id is always the first in the comma separated list and will always be a name value pair delimited by '='
If you want to solve it via substring then you shouldn't use a predefined .substring(4,9). Use something like that:
String item = "id=17985, title=the matrix, year=1999";
String id = item.substring(item.indexOf("id=") + 3, item.indexOf(" ", item.indexOf("id=") + 3) - 1);
System.out.println("Your ID is: " + id);
// Works also for "test=asdf, id=17985, title=the matrix, year=1999"
It gets the String between "id=" and the next " " (space).

Need to get one by one column value from getadapter in Listview in Android

I have filled the listview using the code given below, but I'm unablee to get back the values from list because getadpter written an object. From the object I didnt able to get one by one column value.
Code for filling the listview:
String pkManifest = manifest.pkManifestNo;
ArrayList<HashMap<String, String>> alist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
manifest_helper = new manifest_helper(this);
cursor = manifest_helper.GetDeliveriesAgainstManifest(pkManifest);
cursor.moveToFirst();
for (int i = 0; i < cursor.getCount(); i++) {
map = new HashMap<String, String>();
map.put("Deliv_Address",
cursor.getString(cursor.getColumnIndex("Address")));
map.put("Deliv_Time",
cursor.getString(cursor.getColumnIndex("Time")));
map.put("Deliv_Order",
cursor.getString(cursor.getColumnIndex("DeliveryOrder")));
map.put("Deliv_IsCustomerPickup",
cursor.getString(cursor.getColumnIndex("IsCustomerPickup")));
map.put("Deliv_FKDeliveryStatus",
cursor.getString(cursor.getColumnIndex("FKDeliveryStatus")));
map.put("Deliv_PKDelivery",
cursor.getString(cursor.getColumnIndex("PKDelivery")));
alist.add(map);
cursor.moveToNext();
}
sd = new SimpleAdapter(this, alist, R.layout.deliveries_list_row,
new String[] { "Deliv_Address", "Deliv_Time",
"Deliv_Order", "Deliv_IsCustomerPickup",
"Deliv_FKDeliveryStatus", "Deliv_PKDelivery" },
new int[] { R.id.tv_Deliv_Address, R.id.tv_Deliv_Time,
R.id.tv_Deliv_Order,
R.id.tv_Deliv_IsCustomerPickup,
R.id.tv_Deliv_FKDeliveryStatus,
R.id.tv_Deliv_PKDelivery });
//selectedAdapter = new SelectedAdapter(this, 0, alist);
//selectedAdapter.setNotifyOnChange(true);
ListDeliveries.setAdapter(sd);
Code for getting the value on onItemSelected is written like this:
private OnItemSelectedListener mDeviceSelectedListener = new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> av, View v, int arg2,long arg3) {
Object o = av.getAdapter().getItem(arg2);
String keyword = o.toString();
MessageBox("You selected: " + keyword);
}
private OnItemClickListener mDeviceClickListener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3) {
HashMap result = (HashMap) av.getAdapter().getItem(arg2);
pkDelivery = result.get("Deliv_PKDelivery").toString();
pbDeliveryOrder=result.get("Deliv_Order").toString();
isCustomerPickup=result.get("Deliv_IsCustomerPickup").toString();
if ("false".equals(isCustomerPickup))
{
customerPickup="false";
pbPickUp="false";
}
else
{
customerPickup="true";
pbPickUp="true";
}
launchDelivery_header(pkDelivery);
}
};
This can be done by getting the adapter value to a hash map and get it one by one

Categories

Resources