ListView的只有一个列表条目播放按钮的作品 [英] ListView only one list entry play button works
问题描述
我试图做一个ListView活动之后从该网站的例子
的http://cyrilmottier.com/2011/11/23/listview-tips-tricks-4-add-several-clickable-areas/
在我使用的数据来自我的数据库,并使用一个BaseAdapter一切似乎正常工作(该onListItemClick,TextView的加载我的数据),但我的播放按钮在列表项的权不会干活。正在使用的FrameLayout我的列表项的XML是否有帮助。
--- ---更新
这些问题的答案都没有解决我的问题,但摆弄周围后,我拿到了第一项播放按钮的工作,但只有第一个作品other条目播放按钮不起作用。
这是新的codeS为我的名单活动和XML。
PlayAFriend活动
包com.fullfrontalgames.numberfighter;
进口com.fullfrontalgames.numberfighter.DBAdapter;
进口com.fullfrontalgames.numberfighter.R;进口android.app.ListActivity;
进口android.content.Intent;
进口android.database.Cursor;进口android.os.Bundle;进口android.support.v4.widget.SimpleCursorAdapter;
进口android.view.View;
进口android.widget.AdapterView;
进口android.widget.AdapterView.OnItemClickListener;进口android.widget.Button;
进口android.widget.ListAdapter;
进口android.widget.ListView;进口android.widget.Toast;公共类PlayAFriend扩展ListActivity {
DBAdapter DBAdapter;
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
// TODO自动生成方法存根
super.onCreate(savedInstanceState);
的setContentView(R.layout.list_items); 最后DBAdapter DB =新DBAdapter(本);
DBAdapter = db.open();
ListView控件FriendLV =(ListView控件)findViewById(android.R.id.list);
按钮PLAYBUTTON =(按钮)findViewById(R.id.playbutton); FriendLV.setOnItemClickListener(新OnItemClickListener(){ @覆盖
公共无效onItemClick(适配器视图<>为arg0,ARG1观,诠释ARG2,
长ARG3){
// TODO自动生成方法存根
Toast.makeText(getBaseContext(),测试,Toast.LENGTH_SHORT).show();
} });
playbutton.setOnClickListener(新View.OnClickListener(){ @覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
startActivity(新意图(com.fullfrontalgames.numberfighter.Fightattacker));
}
});
光标friendslist = db.GetAllFriends(); 的String [] =由新的String [] {朋友}; //你的专栏/列在这里
INT []为= INT新[] {} R.id.textview_friends; @燮pressWarnings(德precation)
ListAdapter的CursorAdapter =新SimpleCursorAdapter(这一点,R.layout.list_items,friendslist,从到,0);
FriendLV.setAdapter(CursorAdapter的);
}
}
list_items XML
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:descendantFocusability =blocksDescendants
机器人:方向=垂直> < ListView控件
机器人:ID =@机器人:ID /列表
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直> < /&的ListView GT; <的FrameLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:填充=5DP
机器人:背景=@绘制/ searchimageview
机器人:方向=垂直><的TextView
机器人:ID =@ + ID / textview_friends
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字颜色=@彩色/黑白
机器人:文字样式=大胆
机器人:TEXTSIZE =40dp
机器人:layout_gravity =中心/><按钮
机器人:ID =@ + ID / PLAYBUTTON
机器人:layout_width =60dp
机器人:layout_height =60dp
机器人:layout_gravity =右
机器人:背景=@绘制/ PLAYBUTTON/>
< /&的FrameLayout GT;< / LinearLayout中>
更新
对不起,我迟到更新,但我加入了Android的sovled我自己这个问题:onclick属性到我的播放按钮,然后在我的类中定义的公共onButtonClick方法
<按钮
机器人:ID =@ + ID / PLAYBUTTON
机器人:layout_width =60dp
机器人:layout_height =60dp
机器人:layout_gravity =右
安卓的onClick =OnButtonClick
机器人:背景=@绘制/ PLAYBUTTON/>
类
公共无效OnButtonClick(查看视图){
startActivity(新意图(
com.fullfrontalgames.numberfighter.Fightattacker));
}
I'm trying to make a ListView activity following the example from this website
http://cyrilmottier.com/2011/11/23/listview-tips-tricks-4-add-several-clickable-areas/
in which I'm using data from my database and using a BaseAdapter everything seems to work fine (the onListItemClick,the textview loading my data) but my "play" button on the right of the list items will not work.I am using a framelayout in my list-items xml if that helps.
---UPDATE---
None of those answers solved my question but after fiddling around I got the first entry play button working but the other entry play buttons do not work only the first one works. Here is the new codes for my list activity and xml.
PlayAFriend Activity
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>
Update
Sorry for the late update but I sovled this issue on my own by adding a android:onClick attribute to my play button and then defining the public onButtonClick method in my class.
<Button
android:id="@+id/playbutton"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="right"
android:onClick="OnButtonClick"
android:background="@drawable/playbutton" />
Class
public void OnButtonClick(View view) {
startActivity(new Intent(
"com.fullfrontalgames.numberfighter.Fightattacker"));
}
这篇关于ListView的只有一个列表条目播放按钮的作品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!