我有一个应用程序,它是从 Android 手机的联系人列表中检索到的联系人姓名列表。
我试图添加TextView,它就像ListView上方的标题和TextView下方的Button。TextView 和 Button 在列表中的每个名称下方重复出现。看起来像这样
不仅如此,文本视图在列表上方,按钮也在列表下方。这很奇怪。我不确定如何使列表上方的 TextView 和按钮仅位于列表下方。
哦,是的,请看一下我的 java 和 xml 布局代码,谢谢
——contacts_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/light_goldenrod"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textInform"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose a Friend to Create an Event"
android:textColor="@color/dark_purple"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:stackFromBottom="false"
android:transcriptMode="normal" />
<TextView
android:textColor="@color/dark_purple"
android:id="@+id/contactName"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btnMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/yellow_btn"
style="@style/ButtonText"
android:text="Main Menu" />
</LinearLayout>
联系人列表.java
public class ContactsList extends ListActivity
{
TextView contactName;
ListView list;
final Context context = this;
Cursor cursor;
BuddyDBAdapter buddyDB = new BuddyDBAdapter(this);
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.contacts_list);
list = (ListView) findViewById(android.R.id.list);
Uri allContacts = Uri.parse("content://contacts/people");
Cursor c = managedQuery(allContacts, null, null, null, null);
String[] columns = new String[] {ContactsContract.Contacts.DISPLAY_NAME};
int[] views = new int[] {R.id.contactName};
startManagingCursor(c);
SimpleCursorAdapter friendsAdapter = new SimpleCursorAdapter(this, R.layout.contacts_list, c, columns, views);
this.setListAdapter(friendsAdapter);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id)
{
buddyDB.open();
long name_id;
super.onListItemClick(l, v, position, id);
Cursor cursor = null;
cursor = (Cursor) l.getItemAtPosition(position);
Intent intent = new Intent(ContactsList.this, Create_Events.class);
intent.putExtra("name", cursor.getString(cursor.getColumnIndex(buddyDB.KEY_NAME)));
startActivity(intent);
Cursor c = ((SimpleCursorAdapter)l.getAdapter()).getCursor();
c.moveToPosition(position);
TextView contactName = (TextView) v.findViewById(R.id.contactName);
String NameValue = contactName.getText().toString();
name_id = buddyDB.insertNames(NameValue);
buddyDB.close();
}
}
请帮我解决一下这个。
提供的任何帮助将不胜感激。谢谢 =)