two textviews in listview with arrayadapter and arraylist
i m displaying a listview with two textviews .the first textview is used for displaying the name of the location and the second one is for displaying address. i anm retrieving values from database and adding those values in an arraylist. i used a custom arrayadapter class named myadapter inflated the two textviews there but when i set the textviewresourse id of one of the textview i get both the values in a single textview. i want them in sepetate textviews. here is my code in display activity in which i am adding values in an arraylist
c.move(3);
// x1=c.getColumnIndex("_id");
// y1=c.getColumnIndex("latitude");
// z1=c.getColumnIndex("longiitude");
// w1=c.getColumnIndex("address");
x = c.getColumnName(0);
y = c.getColumnName(1);
z = c.getColumnName(2);
w = c.getColumnName(3);
n=c.getColumnName(4);
// tv_id.setText(x.toString().toUpperCase());
//tv_lat.setText(y.toString().toUpperCase());
//tv_lon.setText(z.toString().toUpperCase());
// tv_add.setText(w.toString().toUpperCase());
if(c.moveToFirst())
{
do
{
a = c.getInt(0);
b1 = c.getDouble(1);
c1 = c.getDouble(2);
e = c.getString(3);
f=c.getString(4);
results.add(e+"\n"+f);
}
while (c.moveToNext()); }
Myadapter adapter=new Myadapter(this, R.layout.row,R.id.text2, results);
lv.setBackgroundColor(Color.WHITE);
//lv.setT开发者_开发知识库extFilterEnabled(true);
lv.setCacheColorHint(Color.WHITE);
lv.setAdapter(adapter);
here R.id.text2 is id of the second textview. here is my code in myadapter class
public Myadapter(Context context, int resource, int textViewResourceId,
List<String> results) {
super(context, resource, textViewResourceId, results);
// TODO Auto-generated constructor stub
this.context=context;
this.results=results;
}
private List<String> results;
Context context;
private static final String LayoutInflater = null;
@Override
public View getView(final int position, View convertView, ViewGroup viewGroup) {
String name=results.get(position);
String address=results.get(position);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row, null);
}
TextView tv11 = (TextView) convertView.findViewById(R.id.text11);
tv11.setText(name);
TextView text2 = (TextView) convertView.findViewById(R.id.text2);
text2.setText(address);
pls help me. here is the row.xml
<?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"
>
<TextView
android:id="@+id/text11"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="#000000"
/>
<TextView
android:id="@+id/text2"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp"
android:textColor="#000000"
/>
<Button android:text="Delete" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:focusable="false" android:focusableInTouchMode="false"
></Button>
</LinearLayout>
pls help me i want name to appear in first textview and address in the second. pls help me. thanks and regards
change your layout
android:id="@+id/text2"
android:layout_alignParentRight="true"
in your second text view. you have aligned both textviews to left. change the alignment of the second textview as mentioned above. but still you will encounter overlapping if one of the text is huge.
精彩评论