我正在尝试使用姓名和数字填充两行列表。
我已完成此部分,但我想在点击特定项目时拨打这些数字。
我知道单行列表的这种方法,但我发现两行很难。
这是一个截图:http://imgur.com/vn6zDvu
package com.example.tushar.twolinelist;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
public class MainActivity extends ListActivity {
private SimpleAdapter sa;
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.list1);
lv= (ListView) findViewById(R.id.listView);
HashMap<String, String> item;
for (int
i = 0; i < nameandmubers.length; i++) {
item = new
HashMap<String, String>();
item.put("line1",
nameandmubers[i][0]);
item.put("line2",
nameandmubers[i][1]);
list.add(item);
}
sa = new SimpleAdapter(this, list, R.layout.list1,
new String[]{"line1", "line2"},
new int[]{R.id.text1, R.id.text2});
setListAdapter(sa);
}
private String[][] nameandmubers = {{"mehadi", "0123565"},
{"sagor", "01615"}, {"ovi", "2356565"}, {"hamidul", "25341"},
};
}
&#13;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_marginBottom="10dp"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ff1483d1"
android:textSize="25dp"
android:padding="0dp"
android:text="@string/hello"
android:id="@+id/text1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ffffb14d"
android:padding="0dp"
android:textSize="22dp"
android:text="@string/hello"
android:id="@+id/text2"/>
</LinearLayout>
&#13;
答案 0 :(得分:0)
试试这个!
lv.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,int position, long arg3)
{
String mynumber= //use something like a mutlidimensional array eg. String with value as 'position'
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(mynumber));
startActivity(intent);
}
这可能会有所帮助!