我想创建一个类似于此处所示的 UIhttp://appsreviews.com/wp-content/uploads/2010/08/Cures-A-Z-App-for-iPhone.jpg
我开始尝试将两个自定义列表并排放置,就像在这段代码中一样
import java.util.ArrayList;
import java.util.List;
import java.util.WeakHashMap;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class Emp extends Activity {
/** Called when the activity is first created. */
private String tableName = DBHelper.tableName;
private SQLiteDatabase newDB;
public static WeakHashMap<String, Empbook> temp = new WeakHashMap<String, Empbook>();
final List<Empbook> listOfEmpbook = new ArrayList<Empbook>();
final List<String> listOfAlphabets = new ArrayList<String>();
TextView txt;
EmpbookAdapter adapter = new EmpbookAdapter(this, listOfEmpbook);
Integer pos;
Integer count=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txt=(TextView)findViewById(R.id.textView1);
ListView list = (ListView) findViewById(R.id.ListView01);
ListView alist = (ListView) findViewById(R.id.ListView02);
list.setClickable(true);
alist.setClickable(true);
AlphabetListAdapter alphabetadapter = new AlphabetListAdapter(this,
listOfAlphabets);
list.setAdapter(adapter);
alist.setAdapter(alphabetadapter);
字母表适配器用于在屏幕右侧显示字母表的列表。
我的 XML 如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="TextView" android:id="@+id/textView1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<ListView android:id="@+id/ListView01" android:layout_width="280dp"
android:orientation="vertical" android:layout_height="wrap_content"></ListView>
<ListView android:id="@+id/ListView02" android:layout_width="wrap_content"
android:orientation="vertical" android:paddingLeft="282dp"
android:layout_height="wrap_content"></ListView>
</LinearLayout>
出现的问题是一次只有一个视图(前面放在上面 xml 中的视图会显示,而另一个视图不会出现)。
有人可以把我推向正确的方向吗?
编辑:我尝试将列表的权重设置为 0,将另一个设置为 1,它现在可以部分工作,我可以看到两个列表,但是其中一个列表没有填充....如果我工作,将更新出来。
在下面发布了一个答案(尽管有一个列表视图被删除。)检查一下。