【问题标题】:Android footer with onclickListener带有 onclickListener 的 Android 页脚
【发布时间】:2012-02-17 04:57:46
【问题描述】:

我已经为我的列表视图设置了一个页脚,接下来我将为其设置一个 onclicklistener,它将播放声音,然后转到我的下一个活动,但无法让 onclicklistener 为页脚工作。我已经成功地完成了其他活动,但这给我带来了麻烦,我希望发布代码,有人可以解释我做错了什么。我已经尝试了我在网上找到的所有修复程序,但似乎没有任何效果。

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);
    }

提前 TY,顺便说一句,如果我取出 onclicklistener,我的页面会显示页脚,但如果不修复此步骤就无法继续执行程序

【问题讨论】:

    标签: android listview onclick media-player footer


    【解决方案1】:

    如果您在 XML 中定义按钮,请将 android:onClick="onClick" 添加到其中

    【讨论】:

    • 你太棒了!我从来没有意识到这是我需要在 xml 中设置的东西。
    猜你喜欢
    • 1970-01-01
    • 2011-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多