Monday, June 13, 2011

[android-developers] How to customize the list view...list view resource id is invalid???

HI All,
i m developing a list view and on top, it will have a auto complete
textview, when user clicks on a certain item from the list, i want to
display it in that auto complete text field. but i m getting some
error..pls advice me..my codes are


right now i m unable to load the view..so i have just written the code
for the click on list item..

Thanks

**************package com.example;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class HelloListView extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


ListView lv= (ListView) findViewById(R.id.listview);

lv.setAdapter(new ArrayAdapter<String>(this, R.id.listview,
COUNTRIES));

lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView)
view).getText(),
Toast.LENGTH_SHORT).show();
}
});
}
static final String[] COUNTRIES = new String[] {
"Afghanistan", "Albania", "Algeria", "American Samoa"};
}

***********************xml file

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout android:id="@+id/main1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="4dip" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<AutoCompleteTextView android:id="@+id/searchText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true" android:textSize="16sp"
android:autoText="false"
android:capitalize="none" android:layout_alignParentLeft="true"
android:scrollHorizontally="true">

</AutoCompleteTextView>

<Button android:id="@+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=""

android:layout_alignParentRight="true">
</Button>

<ListView android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="10dp"
android:textSize="16sp">
</ListView>
</RelativeLayout>

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate