Hi, android is new for me. I am trying to develop a program on 1.5 platform but still in progress, plz guide me.
I have some information in following format
"item1","description1"
"item2","description2"
"item3","description3"
"item4","description4"
.
.
.
.
I want to show them on screen, I dont know which is recommended way to do this. After google I found 2 method. but I failed to successfully implement any of one.
Method 1
I break both columns data into 2 different arrays, then populate listactivity with array of column 1, enable filter & on clicked event I want to raise alert which should show Text clicked in tilte & desc from 2nd array as msg body based on position. But here is problem if using filter index becomes reinitialize :-(, and there didnot find another way to get text of that row.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, Names));
getListView().setTextFilterEnabled(true);
}
public void onListItemClick(ListView parent, View v, int position, long id) {
Builder builder = new AlertDialog.Builder(this);
builder.setTitle(Names[position]);
builder.setMessage(description[position] + " -> " + position );
builder.setPositiveButton("ok", null);
builder.show();
}
<?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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
its not picking right item from position if filter used :-(, plz guide Can you share source code of this
Method B
Here I tried to generate list row from XML , but giving error that 1.5 jar file didnot allow modification :-(
public View getView(int position, View convertView, ViewGroup parent) {
/*
ViewInflate inflater=context.getViewInflate();
View row=inflater.inflate(R.layout.row, null, null);
*/
View row = (View) convertView;
if (row==null) {
LayoutInflater inflater=context.getLayoutInflater();
// LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.row,null);
}
TextView label=(TextView)row.findViewById(R.id.label);
label.setText(items[position]);
TextView description=(TextView)row.findViewById(R.id.description);
description.setText(items[position]);
// ImageView icon=(ImageView)row.findViewById(R.id.icon);
// icon.setImageResource(R.drawable.delete);
return(row);
}
Plz suggest what is a right way to acconplish this, so app can show desc of item , has filter too. Plz share If you have any shouce code for this