android listview下面的按钮

android listview下面的按钮,android,listview,Android,Listview,所以我尝试了所有其他帖子,但都不起作用,有人能告诉我为什么按钮会进入listview吗 我的布局的代码是: <FrameLayout xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" and

所以我尝试了所有其他帖子,但都不起作用,有人能告诉我为什么按钮会进入listview吗

我的布局的代码是:

<FrameLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#5eff6c"
tools:context=".FriendActivity">


<ListView
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:id="@+id/listView"
    android:layout_gravity="center_horizontal|top"
    android:background="#5eff6c" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/name"
    android:layout_gravity="center_vertical"
    android:textSize="16dp"
    android:textIsSelectable="false" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button"
    android:layout_gravity="center" />

</FrameLayout>

现在看起来是这样的:

我想要这个:

编辑: Java代码:

public class FriendActivity extends ListActivity {

private static final String TAG_NAME = "name";
protected void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);

    ArrayList<HashMap<String, String>> names = null;
        try {
            String test = new sendData().execute().get();
            JSONArray jArray = new JSONArray(test);
            Log.d("NOOO", String.valueOf(test));

            names = new ArrayList<HashMap<String, String>>();
            JSONObject object;
            for (int i = 0; i < jArray.length(); i++) {
                object = jArray.getJSONObject(i);
                Log.d("YES", String.valueOf(object));

                String name = object.getString(TAG_NAME);

                HashMap<String, String> map = new HashMap<String, String>();

                map.put(TAG_NAME, name);

                names.add(map);
        }

        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }

    ListAdapter adapter = new SimpleAdapter(this, names,
            R.layout.activity_friend,
            new String[]{TAG_NAME}, new int[]{
            R.id.name});

    setListAdapter(adapter);

    // selecting single ListView item
    ListView lv = getListView();

    // Launching new screen on Selecting Single ListItem
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {

        }
    });
}

}
公共类FriendActivity扩展了ListActivity{
私有静态最终字符串标记_NAME=“NAME”;
创建时受保护的void(Bundle savedInstanceState){
this.requestWindowFeature(Window.FEATURE\u NO\u TITLE);
super.onCreate(savedInstanceState);
arraylistnames=null;
试一试{
字符串测试=新建sendData().execute().get();
JSONArray jArray=新JSONArray(测试);
Log.d(“NOOO”,String.valueOf(test));
名称=新的ArrayList();
JSONObject对象;
for(int i=0;i

感谢您的帮助

问题在于您正在将该布局传递给您的
列表视图
的每个布局:

ListAdapter adapter = new SimpleAdapter(this, names,
            R.layout.activity_friend,
            new String[]{TAG_NAME}, new int[]{
            R.id.name});
您要做的是这样设置布局:

setContentView(R.layout.activity_friend);
这样,它将被设置为活动,并且您的活动将看起来像您在xml中创建的活动

另外,用一个
TextView
制作另一个简单布局,并将其传递给适配器,这样您的
ListView
中也会有一个文本。或者您可以从android使用此布局:
android.R.layout.simple\u list\u item\u 1

对于按钮重力,我认为您应该使用:

android:layout_gravity="center_horizontal|bottom"

别忘了从上面发布的版面中删除textview,因为你不再需要它了。

你能把java代码也发布出来吗?我把“setContentView(R.layout.activity_friend);”放在哪里?在onCreate中,就在下面:super.onCreate(savedInstanceState);好的,但是我如何使SimpleAdapter不为每个listview项目使用布局?正如我前面所说的,只需将适配器中的R.Layout.activity\u friend替换为android.R.Layout.simple\u list\u item\u 1即可:)