带有onclickListener的Android页脚
我已经为我的列表视图设置了一个页脚,接下来我将为它设置一个onclicklistener,它将播放一个声音,然后转到我的下一个活动,但无法让onclicklistener为页脚工作。我已经在其他活动中成功地做到了这一点,但这次给我带来了麻烦。我希望发布代码,有人能解释我做错了什么。我已经尝试了我在网上找到的每一个修复方法,但似乎没有任何效果带有onclickListener的Android页脚,android,listview,onclick,media-player,footer,Android,Listview,Onclick,Media Player,Footer,我已经为我的列表视图设置了一个页脚,接下来我将为它设置一个onclicklistener,它将播放一个声音,然后转到我的下一个活动,但无法让onclicklistener为页脚工作。我已经在其他活动中成功地做到了这一点,但这次给我带来了麻烦。我希望发布代码,有人能解释我做错了什么。我已经尝试了我在网上找到的每一个修复方法,但似乎没有任何效果 import java.util.ArrayList; import java.util.List; import android.app.ListAct
import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class editpage extends ListActivity {
//editCount still unused at time but will grab data inputted into edittext fields
int editCount;
private dbadapter mydbhelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_list);
mydbhelper = new dbadapter(this);
mydbhelper.open();
fillData();
}
private void fillData() {
Cursor e = mydbhelper.getUserWord();
startManagingCursor(e);
// Create an array to specify the fields we want to display in the list
String[] from = new String[] {dbadapter.KEY_USERWORD,};
// an array of the views that we want to bind those fields to
int[] to = new int[] {R.id.textType,};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter editadapter =
new SimpleCursorAdapter(this, R.layout.edit_row, e, from, to);
ListView list = getListView();
View footer = getLayoutInflater().inflate(R.layout.footer_layout, list, false);
list.addFooterView(footer);
setListAdapter(editadapter);
//still not used, need to get onclicklistener working since this will be used to send data to next activity
editCount = e.getCount();
}
public void onClick(View footer){
final MediaPlayer editClickSound = MediaPlayer.create(this, R.raw.button50);
editClickSound.start();
};
//This should not be needed since clicking on items in list view will not have a function but read someone to put my footer onclick in here but didn't work for me
@Override
protected void onListItemClick(ListView list, View v, int position, long id)
{
super.onListItemClick(list, v, position, id);
//final Intent intent = new Intent(this, title.class);
//startActivityForResult(intent, position);
}
提前,顺便说一句,如果我取出onClick Listener,我的页面会显示页脚,但如果不修复此步骤,就无法继续使用程序如果您用XML定义按钮,请将
android:onClick=“onClick”
添加到它中您的精彩!我从未意识到我需要在xml中设置它。