在我的应用程序中,我从解析中获取数据,其中一些行包含Employees的描述而一些不包含。
我想说的是,如果在一个项目的Parse上没有描述,那么该列表项就不能被点击或者可以执行onItemClick
功能。
或者只有那些可以点击那些我从Parse获得Description
的人。
我真的不知道如何实现这一点,这件事在Android中是否可行。
我已完成从解析中显示数据并在Activity中显示的所有其他工作 但对此却一无所知。 请帮助
我的全班守则在下面给出
public class FragmentActivity_DayFirst extends Fragment implements
OnItemClickListener {
Bitmap bmp;
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ArrayAdapter<String> adapter;
AgendaListAdapter adapter2;
Fragment fr;
FragmentManager fm;
FragmentTransaction fragmentTransaction;
private List<GetSet> agendaList = new ArrayList<GetSet>();
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_fragment__dayfirst,
container, false);
new RemoteDataTask().execute();
return view;
}
// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(getActivity());
// Set progressdialog title
mProgressDialog.setTitle("Loading Details of 1st Day");
// Set progressdialog message
mProgressDialog
.setMessage("Wait.. It May Take a while depending on your Bandwidth");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"Agendas");
query.whereEqualTo("day", "August 7th, 2015");
query.orderByAscending("createdAt");
try {
ob = query.find();
if (ob != null) {
for (ParseObject agendas : ob) {
// ParseFile image = (ParseFile)
// complain.get("imageURL");
GetSet agendaGetSet = new GetSet();
agendaGetSet.setStartTime((String) agendas
.get("startTime"));
Log.v("post", (String) agendas.get("startTime"));
agendaGetSet
.setEndTime((String) agendas.get("endTime"));
Log.v("category", (String) agendas.get("endTime"));
agendaGetSet.setEventTitle((String) agendas
.get("description"));
Log.v("post", (String) agendas.get("description"));
agendaList.add(agendaGetSet);
}
} else {
Log.v("post", "No Results");
}
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
Log.v("post", "After query post");
listview = (ListView) getView().findViewById(R.id.firstlistview);
// Pass the results into ListViewAdapter.java
adapter2 = new AgendaListAdapter(getActivity(), agendaList);
// Binds the Adapter to the ListView
listview.setAdapter(adapter2);
// Close the progressdialog
mProgressDialog.dismiss();
// Item Click Listener for the listview
OnItemClickListener itemClickListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View container,
int position, long id) {
// Getting the Container Layout of the ListView
LinearLayout linearLayoutParent = (LinearLayout) container;
// Getting the inner Linear Layout
LinearLayout linearLayoutChild = (LinearLayout) linearLayoutParent
.getChildAt(0);
// Getting the inner Linear Layout
RelativeLayout relativeLayoutChild = (RelativeLayout) linearLayoutParent
.getChildAt(1);
// Getting the Country TextView
TextView tv_title = (TextView) relativeLayoutChild
.getChildAt(0);
TextView startTime = (TextView) linearLayoutChild
.getChildAt(0);
TextView endTime = (TextView) linearLayoutChild
.getChildAt(1);
String mTitle = tv_title.getText().toString();
String mstartTime = startTime.getText().toString();
String mendTime = endTime.getText().toString();
Intent intent = new Intent(getActivity(), EventDetail.class);
intent.putExtra("title", mTitle);
intent.putExtra("starttime", mstartTime);
intent.putExtra("endtime", mendTime);
startActivity(intent);
Toast.makeText(getActivity(),
mTitle + " " + mstartTime + " " + mendTime,
Toast.LENGTH_SHORT).show();
}
};
listview.setOnItemClickListener(itemClickListener);
}
}
public void onStart() {
super.onStart();
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:1)
您可以在适配器类中执行的操作是覆盖以下函数
@Override
public boolean isEnabled(int position) {
// here you can implement logic and can return true and false
// if you will return true then row will be clickable
// if you return false the row will be not clickable
return true;
}