我正在使用以下代码: -
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newsfeed);
setAllControlls();
myPrefs = this.getSharedPreferences(
AppConstants.MYPREF, MODE_WORLD_READABLE);
userid = myPrefs.getString(AppConstants.USER_ID, "");
if(checkInternet(NewFeeds.this))
{
new callNewsfeeddata().execute(userid);
}
else
{
Toast.makeText(NewFeeds.this,"Please Check Your Internet Connection",Toast.LENGTH_LONG).show();
}
objlistview.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
if(checkInternet(NewFeeds.this))
{
new callNewsfeeddata().execute(userid);
}
else
{
Toast.makeText(NewFeeds.this,"Please Check Your Internet Connection",Toast.LENGTH_LONG).show();
}
}
});
objHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case AppConstants.UPDATE_ADDRESS:
if (!((String) msg.obj).equals("0")) {
System.out.println("inside---" + objlocationvalue);
objlocationvalue = (String) msg.obj;
} else {
objlocationvalue = "1";
}
break;
}
}
};
objLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
}
private void setAllControlls() {
objlistview = (PullToRefreshListView) findViewById(R.id.newsfeedlistview);
objlistview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
long arg3) {
int pos1=pos-1;
NewsFeedModle objnewsfeedmodle = objlist.get(pos);
String type = objnewsfeedmodle.getType();
if(type.equalsIgnoreCase("job"))
{
String postid = objnewsfeedmodle.getJobId();
Intent objintent = new Intent(NewFeeds.this,ShowNewPostJobDetails.class);
Bundle objbundle = new Bundle();
objbundle.putString("postid", postid);
objbundle.putString("from","newsfeed");
objintent.putExtras(objbundle);
startActivity(objintent);
}
if(type.equalsIgnoreCase("deals"))
{
String postid = objnewsfeedmodle.getDealid();
Intent objintent = new Intent(NewFeeds.this,ShowNewFindDeal.class);
Bundle objbundle = new Bundle();
objbundle.putString("postid", postid);
objbundle.putString("from","newsfeed");
objintent.putExtras(objbundle);
startActivity(objintent);
}
if(type.equalsIgnoreCase("stuff"))
{
String postid = objnewsfeedmodle.getStuffId();
Intent objintent = new Intent(NewFeeds.this,ShowNewFindStuff.class);
Bundle objbundle = new Bundle();
objbundle.putString("postid", postid);
objbundle.putString("from","newsfeed");
objintent.putExtras(objbundle);
startActivity(objintent);
}
}
});
}
private class callNewsfeeddata extends
AsyncTask<String, Void, List<NewsFeedModle>> {
ProgressDialog objprogress = new ProgressDialog(NewFeeds.this);
AppRequestHandler objApprequest = new AppRequestHandler();
List<NewsFeedModle> objresponce = new ArrayList<NewsFeedModle>();
@Override
protected void onPreExecute() {
objprogress.setMessage("Please Wait While Loading...");
objprogress.show();
}
@Override
protected List<NewsFeedModle> doInBackground(String... params) {
objresponce = objApprequest.newsFeedRequest(params[0]);
return objresponce;
}
@Override
protected void onPostExecute(List<NewsFeedModle> result) {
if (objprogress.isShowing()) {
objprogress.dismiss();
}
if(objlist!=null && objlist.size()!=0)
{
objlist.clear();
}
String msgcount="";
if (result != null)
{
objlist=result;
if(objlist.size()==0)
{
Log.i("check",""+objlist.size());
Log.i("check22222",""+result.size());
}
if(objlist!=null && objlist.size()!=0)
{
msgcount = objlist.get(0).getMessagescount();
}
TabActivity tab=(TabActivity) getParent();
TextView tv=(TextView) tab.findViewById(R.id.notificationmsg);
tv.setText(msgcount);
Editor objedit = myPrefs.edit();
objedit.putString(AppConstants.MESSAGECOUNT, msgcount);
objedit.commit();
objnewsFeedAdapter = new NewsFeedAdapter(NewFeeds.this,objlist,(float)objlattvalue,(float)objlongvalue,objlocationvalue);
objlistview.setAdapter(objnewsFeedAdapter);
objnewsFeedAdapter.notifyDataSetChanged();
objlistview.onRefreshComplete();
}
}
}
我已经在setAllContrill方法中定义了OnItemClickLIstener,但它没有工作.listView是无法点击任何人建议我。我正在使用github pulltorefresh代码。我无法找出问题是什么,因为在其他地方它正在工作..
答案 0 :(得分:3)
尝试:`
objlistview.getRefreshableView().setOnItemClickListener(new OnItemClickListener...)
答案 1 :(得分:2)
getRefreshableView()
无济于事,因为setOnItemClickListener()
中的PullToRefreshListView
只是一种传递方式:
public void setOnItemClickListener(OnItemClickListener listener) {
mRefreshableView.setOnItemClickListener(listener);
}
我遇到了同样的问题,事实证明我在项目布局中有可点击的元素。在使这个元素不可点击后,它开始起作用。