我正在尝试按照本网站的示例进行 ListView 活动
http://cyrilmottier.com/2011/11/23/listview-tips-tricks-4-add-several-clickable-areas/
在其中我使用数据库中的数据并使用 BaseAdapter 一切似乎都工作正常(onListItemClick,加载我的数据的文本视图)但列表项右侧的“播放”按钮不起作用。我正在使用如果有帮助,我的列表项 xml 中的框架布局。
- -更新 - -
这些答案都没有解决我的问题,但是在摆弄之后,我得到了第一个入口播放按钮,但其他入口播放按钮不起作用,只有第一个起作用。这是我的列表活动和 xml 的新代码。
PlayAFriend 活动
package com.fullfrontalgames.numberfighter;
import com.fullfrontalgames.numberfighter.DBAdapter;
import com.fullfrontalgames.numberfighter.R;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class PlayAFriend extends ListActivity{
DBAdapter DBAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.list_items);
final DBAdapter db = new DBAdapter(this);
DBAdapter = db.open();
ListView FriendLV = (ListView) findViewById(android.R.id.list);
Button playbutton = (Button) findViewById(R.id.playbutton);
FriendLV.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "test", Toast.LENGTH_SHORT).show();
}
});
playbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fullfrontalgames.numberfighter.Fightattacker"));
}
});
Cursor friendslist = db.GetAllFriends();
String[] from = new String[] {"FRIENDS"}; // your column/columns here
int[] to = new int[] {R.id.textview_friends};
@SuppressWarnings("deprecation")
ListAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.list_items, friendslist, from, to,0);
FriendLV.setAdapter(cursorAdapter);
}
}
list_items xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</ListView>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="@drawable/searchimageview"
android:orientation="vertical" >
<TextView
android:id="@+id/textview_friends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="40dp"
android:layout_gravity="center" />
<Button
android:id="@+id/playbutton"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="right"
android:background="@drawable/playbutton" />
</FrameLayout>
</LinearLayout>