我正在尝试构建一个记事本应用程序。在我的布局中有两个 TextView。第一个文本视图只显示一个字符串“Your Saved Entries”,其中第二个 TextView 显示已保存条目的标题。我的问题是第一个 TextView 与已保存条目的所有标题重复。我希望字符串“Your Saved Entries”出现一次,然后显示所有已保存条目的标题。请帮我
这是我的 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="wrap_content"
android:orientation="vertical"
android:paddingRight="3dp"
android:paddingLeft="3dp"
android:paddingTop="15dp"
android:paddingBottom="10dp"
>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/intro" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/postslist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:textSize="20sp"
android:textColor="@android:color/white"
android:gravity="center_vertical"
/>
</LinearLayout>
这是我的活动文件
package com.ex.fastnotes;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.AdapterView.OnItemClickListener;
public class Notesli extends ListActivity {
public static final String ROW_ID = "row_id";
private ListView conListView;
private CursorAdapter conAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
conListView=getListView();
conListView.setOnItemClickListener(viewConListener);
// map each name to a TextView
String[] from = new String[] { "name" };
int[] to = new int[] { R.id.postslist };
conAdapter = new SimpleCursorAdapter(Notesli.this, R.layout.tlist, null, from, to);
setListAdapter(conAdapter); // set adapter
}
@Override
protected void onResume()
{
super.onResume();
new GetContacts().execute((Object[]) null);
}
@Override
protected void onStop()
{
Cursor cursor = conAdapter.getCursor();
if (cursor != null)
cursor.deactivate();
conAdapter.changeCursor(null);
super.onStop();
}
private class GetContacts extends AsyncTask<Object, Object, Cursor>
{
DatabaseConnector dbConnector = new DatabaseConnector(Notesli.this);
@Override
protected Cursor doInBackground(Object... params)
{
dbConnector.open();
return dbConnector.getAllContacts();
}
@Override
protected void onPostExecute(Cursor result)
{
conAdapter.changeCursor(result); // set the adapter's Cursor
dbConnector.close();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.corefile, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
Intent addContact = new Intent(Notesli.this, Corefile.class);
startActivity(addContact);
return super.onOptionsItemSelected(item);
}
OnItemClickListener viewConListener = new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
{
Intent viewCon = new Intent(Notesli.this, ViewNotes.class);
viewCon.putExtra(ROW_ID, arg3);
startActivity(viewCon);
}
};
}