Android AutoCompleteTextView not rendering correctly? - android

Hi I have a AutoCompleteTextView which works fine on my Nexus1. When deploying the code on a Samsung Apollo i5801 the list doesn't display correctly. The data is in the list as I can scroll a little (see pics below).
Here is my CursorAdapter
class VenueSuggestionLitsAdpater extends CursorAdapter implements
Filterable {
private HiTechDatabaseAdapter database;
public VenueSuggestionLitsAdpater(Context context, Cursor c) {
super(context, c);
// database = HiTechDatabaseAdapter.getInstance(JobActivity.this);
// TODO Auto-generated constructor stub
}
#Override
public void bindView(View view, Context context, Cursor cursor) {
int name = cursor.getColumnIndex("name");
int postcode = cursor.getColumnIndex("postcode");
String str = cursor.getString(name) + " - "
+ cursor.getString(postcode);
((TextView) view).setText(str);
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final LayoutInflater inflater = LayoutInflater.from(context);
final TextView view = (TextView) inflater.inflate(
android.R.layout.simple_dropdown_item_1line, parent, false);
int name = cursor.getColumnIndex("name");
int postcode = cursor.getColumnIndex("postcode");
String str = cursor.getString(name) + " - "
+ cursor.getString(postcode);
view.setText(str);
return view;
}
#Override
public CharSequence convertToString(Cursor cursor) {
int columnIndex = cursor.getColumnIndexOrThrow("name");
String name = cursor.getString(columnIndex);
// Log.d("Debug","Convert To String....");
return name;
}
#Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
if (constraint == null) {
Cursor suggestions = HiTechDatabaseAdapter.getInstance(
JobActivity.this).queryVenueName(
HiTechDatabaseAdapter.TABLE_VENUES,
new String[] { "_id", "name", "address", "postcode","venueID" },
"");
return suggestions;
}
Cursor suggestions = HiTechDatabaseAdapter.getInstance(
JobActivity.this).queryVenueName(
HiTechDatabaseAdapter.TABLE_VENUES,
new String[] { "_id", "name", "address", "postcode","venueID" },
constraint.toString());
return suggestions;
}
}
And how I apply my adapter to my AutoCompleteTextView
VenueSuggestionLitsAdpater suggestionsAdapter = new VenueSuggestionLitsAdpater(
JobActivity.this, suggestions);
venuNameSearch.setAdapter(suggestionsAdapter);
Finally my XML layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10px">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/venuetextlabel"
android:text="Venue:"
/>
<AutoCompleteTextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/venuesearch"
android:editable="true"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textcampaign"
android:text="Campaign:"
/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="60px"
android:id="#+id/campaign"
android:drawSelectorOnTop="true"
android:prompt="#string/campaign"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textgender"
android:text="Gender:"
/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="60px"
android:id="#+id/gender"
android:drawSelectorOnTop="true"
android:prompt="#string/gender"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textreason"
android:text="Reason:"/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="60px"
android:id="#+id/reason"
android:drawSelectorOnTop="true"
android:prompt="#string/reason"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/address_line_1"
android:hint="Address Line 1"
android:editable="false"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/address_postcode"
android:hint="Postcode"
android:editable="false"
/>
<Gallery
android:id="#+id/gallery"
android:layout_marginTop="10px"
android:spacing="10px"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="200px"
android:layout_height="60px"
android:id="#+id/submit"
android:text="Submit"
android:textSize="20sp"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10px"
/>
</LinearLayout>
Any help would be much appreciated.
Cheers

Related

How give number to listview items in android

I am new to android . I have an application working with listview and i want to number each list view item.
Like,
1 list item
2 list item
3 list item
MainActivity.java
public class MainActivity extends AppCompatActivity {
private OrderDbManager orderDbManager;
private ListView listView;
private SimpleCursorAdapter adapter;
final String[] from = new String[] { OrderDbHelper.FOOD_NAME,
OrderDbHelper.QUANTITY, OrderDbHelper.PRICE };
final int[] to = new int[] {R.id.tvFoodName, R.id.tvItemQuantity, R.id.tvItemPrice };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
orderDbManager = new OrderDbManager(this);
orderDbManager.open();
final Cursor cursor = orderDbManager.fetch();
listView = (ListView) findViewById(R.id.listView);
listView.setEmptyView(findViewById(R.id.empty));
adapter = new SimpleCursorAdapter(this, R.layout.list_item, cursor, from, to, 0);
adapter.notifyDataSetChanged();
LayoutInflater layoutInflater = getLayoutInflater();
listView.addHeaderView(layoutInflater.inflate(R.layout.cart_header,listView, false));
listView.setAdapter(adapter);
}
public class MyAdapter extends SimpleCursorAdapter {
public MyAdapter(Context context, int layout, Cursor c,
String[] from,int[] to) {
super(context, layout, c, from, to);
}
#Override
public int getCount() {
return 0;
}
#Override
public Object getItem(int arg0) {
return null;
}
#Override
public long getItemId(int arg0) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.list_item, null, true);
TextView txt= (TextView) convertView.findViewById(R.id.tvSlNo);
txt.setText(position + 1);
return convertView;
}
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:minHeight="50dp"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/tvSlNo"
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:textStyle="normal"
android:textColor="#android:color/black"
android:layout_weight="0.1" />
<TextView
android:id="#+id/tvFoodName"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:textStyle="normal"
android:textColor="#android:color/black"
android:text=""/>
<TextView
android:id="#+id/tvItemQuantity"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.15"
android:textStyle="normal"
android:textColor="#android:color/black"
android:gravity="center"/>
<TextView
android:id="#+id/tvItemPrice"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:textStyle="normal"
android:textColor="#android:color/black"
android:text=""/>
</LinearLayout>
i want to set numbering in tvSlNo.
please help
In your getView() method of your listViewAdapter simply use the position variable and set it on your TextView. You may need to add 1 to the position since it starts with 0. So use (position+1) and then set it to your TextView
Though this question may be too late but for other reference purposes.
Check where you have this code: txt.setText(position + 1);
you are close to your solution. You just have to typecast position + 1 to String since setText() only take String alone.

Android - update ListView in onCreate does not work

I have the following code:
public class MainActivity extends Activity {
private ListView list;
private static final String path = Environment.getExternalStorageDirectory().getPath() + File.separator + "BOE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView) findViewById(R.id.listView1);
String books[] = {"Mercedes", "Skoda", "Volkswagen", "Audi", "Citroen", "plik"};
BookArrayAdapter bma = new BookArrayAdapter(this, books);
bma.setNotifyOnChange(true);
list.setAdapter(bma);
if (!new File(path).exists()) {
new File(path).mkdirs();
}
for (int i=0; i<books.length; i++) {
View v = list.getAdapter().getView(i, null, null);
String name = ((TextView)v.findViewById(R.id.row_text)).getText() + "";
for (File f:new File(path).listFiles()) {
if (f.isFile()) {
Button b = (Button) v.findViewById(R.id.row_button);
if (name.equals(f.getName().substring(0, f.getName().length()-4))) {
b.setText("Open");
} else {
b.setText("Download");
}
bma.notifyDataSetInvalidated();
bma.notifyDataSetChanged();
Log.d("AC", b.getText().toString());
}
}
}
}
public class BookArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public BookArrayAdapter(Context context, String[] values) {
super(context, R.layout.row, 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);
final View rowView = inflater.inflate(R.layout.row, parent, false);
final TextView textView = (TextView) rowView.findViewById(R.id.row_text);
textView.setText(values[position]);
rowView.findViewById(R.id.row_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (((Button)v).getText().toString().equals("Open")) {
//open
} else {
//Download
}
}
});
return rowView;
}
}
}
and I have problems in for loop in onCreate. this Log shows correct Download/Open texts depenging on Files in file system. But the graphical representation of this list view does not changing. Here's my layout.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
</ListView>
<RelativeLayout
android:id="#+id/main_linear_blackout"
android:layout_width="match_parent"
android:visibility="invisible"
android:layout_height="match_parent"
android:background="#CC000000" >
<ProgressBar
android:id="#+id/main_progress_startup"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</RelativeLayout>
and my row.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/row_button"
android:orientation="vertical" >
<TextView
android:id="#+id/row_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ProgressBar
android:id="#+id/row_progress"
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="invisible" />
</LinearLayout>
<Button
android:id="#+id/row_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/row_percentage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/row_button"
android:layout_alignBottom="#+id/row_button"
android:layout_alignLeft="#+id/row_button"
android:layout_alignRight="#+id/row_button"
android:layout_alignTop="#+id/row_button"
android:gravity="center"
android:textAlignment="center"
android:textSize="20sp"
android:visibility="invisible" />
</RelativeLayout>
how to update it? What is wrong?
EDIT:
I moved editing single row to getView(...) overrided method on my adapter class. I don't really know why my first idea was wrong, but now it works.

ListView item clicklistener is not working android?

I have a listview which contains a custom adapter which has 6 textviews.
When I put the method for it's item click listener, listview element is not getting clicked. What could be the issue?
This is the list element XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textViewDealerName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textViewDealerNumber1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textViewDealerNumber2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textViewDealerAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textViewDealerPin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textViewDealerCity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textViewDealerState"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
This is the adapter class
public class DealerListAdapter extends BaseAdapter {
Vector<String> dealerName = new Vector<String>();
Vector<String> dealerNum1 = new Vector<String>();
Vector<String> dealerNum2 = new Vector<String>();
Vector<String> dealerAdd = new Vector<String>();
Vector<String> dealerPin = new Vector<String>();
Vector<String> dealerCity = new Vector<String>();
Vector<String> dealerState = new Vector<String>();
private LayoutInflater inflater = null;
Context c;
public DealerListAdapter(Context a, Vector<String> name,
Vector<String> num1, Vector<String> num2, Vector<String> add,
Vector<String> pin, Vector<String> city,
Vector<String> state) {
this.dealerName = name;
this.dealerNum1 = num1;
this.dealerNum2 = num2;
this.dealerAdd = add;
this.dealerPin = pin;
this.dealerCity = city;
this.dealerState = state;
this.c = a;
inflater = (LayoutInflater) a
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return dealerName.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
View row = convertView;
if (row == null) {
row = inflater.inflate(R.layout.dealer_list_element, null);
holder = new ViewHolder();
holder.dName = (TextView) row.findViewById(R.id.textViewDealerName);
holder.dNum1 = (TextView) row
.findViewById(R.id.textViewDealerNumber1);
holder.dNum2 = (TextView) row
.findViewById(R.id.textViewDealerNumber2);
holder.dAdd = (TextView) row
.findViewById(R.id.textViewDealerAddress);
holder.dPin = (TextView) row.findViewById(R.id.textViewDealerPin);
holder.dCity = (TextView) row.findViewById(R.id.textViewDealerCity);
holder.dState = (TextView) row
.findViewById(R.id.textViewDealerState);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
holder.dName.setText("Dealership Name: "
+ dealerName.elementAt(position));
holder.dNum1.setText("Contact Number: "
+ dealerNum1.elementAt(position));
holder.dNum2.setText("Contact Number: " + dealerNum2.elementAt(position));
holder.dNum2.setMovementMethod(LinkMovementMethod.getInstance());
holder.dAdd.setText("Address: " + dealerAdd.elementAt(position));
holder.dPin.setText("Pincode: " + dealerPin.elementAt(position));
holder.dCity.setText("City: " + dealerCity.elementAt(position));
holder.dState.setText("State: " + dealerState.elementAt(position));
return row;
}
public final class ViewHolder {
TextView dName, dNum1, dNum2, dAdd, dPin, dCity, dState;
}
}
My onitemclicklistener
dealerListView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
TextView pin = (TextView) view
.findViewById(R.id.textViewDealerPin);
Log.e("pin text ",pin.getText().toString());
}
});
Activity Lyout
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
tools:context="com.vfconect.locator.DealerListActivity" >
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp" >
<ListView
android:id="#+id/listViewDealer"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</RelativeLayout>
</FrameLayout>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#android:color/white"
android:choiceMode="singleChoice"
android:divider="#D8D8D8" />
</android.support.v4.widget.DrawerLayout>
Solved by adding these lines in the parent layout of listview element
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
Listview onItemClickListener not working

Android: SimpleCursorAdapter.ViewBinder, listview, error

I would like to display a two textView in my ListView depending on the database value.
But in result nothing is displayed (error)
This is my code:
public class ListbookActivity extends ListActivity implements OnQueryTextListener{
private DBHelper database;
private Intent intent;
private ListView listav;
private SimpleCursorAdapter adapter;
private String strclickmenu;
private Cursor cursor;
private Toast t;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] from = new String[] { "titolo", "autore" };
int[] to = new int[] { R.id.name, R.id.surname};
database = new DBHelper(getApplicationContext());
SQLiteDatabase db = database.getReadableDatabase();
//query
cursor = db.query("libreria", null, null, null, null, null, "titolo", null);
cursor.moveToFirst();
listav = (ListView) findViewById(R.id.list);
adapter = new SimpleCursorAdapter(this,R.layout.list_row, cursor,from,to,0);
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
#Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.name) {
String userFullName = cursor.getString(cursor.getColumnIndex("titolo"));
TextView tit = (TextView)view;
tit.setText(userFullName);
return true;
} else if (view.getId() == R.id.surname) {
String userEmail = cursor.getString(cursor.getColumnIndex("titolo"));
TextView aut = (TextView)view;
aut.setText(userEmail);
return true;
} else {
return false;
}
}
});
listav.setAdapter(adapter);
list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/name"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1.51"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/surname"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1.51"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
activity_listbook.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:smoothScrollbar="false"
android:fadingEdge="none"/>
</LinearLayout>
This is the error:
Unable to start activity componentInfo{com.example.mybooks.ListBookActivity} : Java.lang.nullPointerException

ResourceNotFoundException at custom's listview adapter

I have such a activity with my list:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/altOrderslist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
/>
</RelativeLayout>
and I want to make custom listview with the items:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout
android:id="#+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:padding="3dip" >
<TextView
android:id="#+id/altOrderId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rihanna Love the way lie"
android:textColor="#040404"
android:textSize="15dip"
android:textStyle="bold"
android:typeface="sans" />
</LinearLayout>
<!-- Title Of Song -->
<!-- Artist Name -->
<TextView
android:id="#+id/altOrderTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dip"
android:layout_toRightOf="#+id/thumbnail"
android:text="Just gona stand there and ..."
android:textColor="#343434"
android:textSize="10dip" />
<!-- Rightend Duration -->
<TextView
android:id="#+id/altOrderStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dip"
android:gravity="right"
android:textColor="#10bcc9"
android:textSize="10dip"
android:textStyle="bold" />
<!-- Rightend Arrow -->
<TextView
android:id="#+id/altOrderPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/thumbnail"
android:text="Rihanna Love the way lie"
android:textColor="#040404"
android:textSize="15dip"
android:textStyle="bold"
android:typeface="sans" />
</RelativeLayout>
This is my adapter class:
public class OrderAdapter extends ArrayAdapter<Order>{
Context context;
int layoutResourceId;
List<Order> orders = null;
public OrderAdapter(Context context, int layoutResourceId, List<Order> orders) {
super(context, layoutResourceId, orders);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.orders = orders;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
OrderHolder holder = null;
if(row == null)
{
Log.i("I'm in OrderAdapter",Integer.toString(layoutResourceId));
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(R.layout.dash_alt_item, parent, false);
Log.i("I'm in OrderAdapter",Integer.toString(layoutResourceId));
holder = new OrderHolder();
holder.orderId = (TextView)row.findViewById(R.id.altOrderId);
holder.orderTitle = (TextView)row.findViewById(R.id.altOrderTitle);
holder.orderStatus = (TextView)row.findViewById(R.id.altOrderStatus);
holder.orderPrice = (TextView)row.findViewById(R.id.altOrderPrice);
//row.setTag(holder);
}
else
{
holder = (OrderHolder)row.getTag();
}
Order order = orders.get(position);
holder.orderId.setText(order.getOrderid());
holder.orderTitle.setText(order.getTitle());
holder.orderStatus.setText(order.getProcess_status().getProccessStatusTitle());
holder.orderPrice.setText(Float.toString(order.getPrice()));
return row;
}
static class OrderHolder
{
TextView orderId;
TextView orderTitle;
TextView orderStatus;
TextView orderPrice;
}
}
And how I use it in my Activity:
public class DashboardActivityAlt extends Activity{
static List<Order> orders;
List<Order> forPrint = new ArrayList<Order>();
private ListView listView1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dash_alt);
try {
this.getOrderList("1", "10"); **// filling the forPrint list**
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OrderAdapter adapter = new OrderAdapter(this,
R.layout.dash_alt_item, **forPrint**);
listView1 = (ListView)findViewById(R.id.altOrderslist);
listView1.setAdapter(adapter);
}
And I get ResourceNotFoundException at the line holder.orderId.setText(order.getOrderid());
What is the reason of it?
Make sure you are not passing an int to that method. Cast it to a String and will start to work as expected.
The reason is setText() is overloaded it has versions:
setText(int resId)
setText(String text)

Categories

Resources