您需要告诉适配器使用哪个OnShareClickedListener()实现。现在,在您的适配器中,从未将字段mCallback分配给它,或者您需要在适配器中具有setOnSharedClickedListener()方法,然后从mainActivity调用该方法并将其设置为mainActivity的实现,或者需要使用构造函数。
我的建议是使用setter而不是构造函数。因此,您需要做的就是这个。
您的ListAdapter
public class ListAdapter extends baseAdapter implements View.onClickListener { onShareClickedListener mCallback; Context context; public static List<String> url_list; public ListAdapter(Context c, List<String> list) { this.context = c; url_list = list; } public void setonShareClickedListener(onShareClickedListener mCallback) { this.mCallback = mCallback; } public interface onShareClickedListener { public void ShareClicked(String url); } @Override public void onClick(View v) { mCallback.ShareClicked("Share this text."); }}
您的MainActivty
public class MainActivity extends ActionBarActivity implements ListAdapter.OnShareClickedListener{ ListView main_list; List<String> url_list; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); main_list = (ListView) findViewById(R.id.listView); ListAdapter nListAdapter = new ListAdapter(this, url_list); nListAdapter.setonShareClickedListener(this); main_list.setAdapter(nListAdapter); } @Override public void ShareClicked(String url) { Log.e("Test", url); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)