我正在开发一个Android应用程序,因为我有3个选项卡,
1.Invitation tab
2.Event tab
3.Groupchat tab
邀请选项卡包含邀请列表,“事件”选项卡包含事件列表,“组聊天”选项卡包含邀请和事件列表集合。 在我的群组聊天标签中,我有一个图标"下拉"(下拉图标显示在仪表板中),其中包含三个项目"全部,事件,邀请"我用来过滤Groupchat列表项目(它有邀请和事件列表的集合)。现在我需要的是,
当我在ontap&#34;事件项目&#34;(事件项目与下拉图标,类似的邀请项目和下拉列表中显示的所有项目一起出现)时,Groupchat选项卡仅显示事件列表。< / p>
当ontap&#34;邀请项目&#34;邀请列表仅显示
当ontap&#34;所有项目&#34;我需要同时显示邀请和活动列表。
我如何实现这一目标,请向我推荐代码......感谢您的帮助
我的编程代码如下,
public class GroupChatFragment extends Fragment {
private Context context;
private ListView chatListView;
private TextView chatTitle;
private TextView chatPlace;
private TextView chatDate;
private String dateResult;
private List<EventMO> groupEventMoList = new ArrayList<>();
private List<EventMO> eventMOs = new ArrayList<>();
private List<EventMO> invitationMOs = new ArrayList<>();
private EventDelegates eventDelegates = new EventDelegates();
private Gson gson = new Gson();
private ProgressDialog prgDialog;
private ChatDisplayAdapter chatDisplayAdapter;
private ListView GroupEventView;
private SharedPreferences sharedpreferences;
private TextView eventList;
private MessageMO messageMO = new MessageMO();
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.all:
return true;
case R.id.event:
return true;
case R.id.invitation:
return true;
}
return super.onOptionsItemSelected(item);
}
public void Event() {
context = getActivity().getApplicationContext();
DatabaseHelper dbHelper = new DatabaseHelper(context);
final UserMO userMO = dbHelper.getRingeeUserData(1);
eventMOs = gson.fromJson(eventDelegates.getAllEventFromUser(userMO, context), new TypeToken<List<EventMO>>() {
}.getType());
List<EventMO> groupEventMOList = new ArrayList<>();
for (EventMO eventMO : eventMOs) {
groupEventMOList.add(eventMO);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final View view = inflater.inflate(R.layout.chatwindow_tab, container, false);
context = getActivity().getApplicationContext();
sharedpreferences = context.getSharedPreferences(Constants.SHARED_PREFERENCE_NAME,
Context.MODE_PRIVATE);
DatabaseHelper dbHelper = new DatabaseHelper(context);
final UserMO userMO = dbHelper.getRingeeUserData(1);
prgDialog = new ProgressDialog(getActivity());
prgDialog.setMessage("Please wait...");
// Set Cancelable as False
prgDialog.setCancelable(false);
prgDialog.show();
//inviation group for user
new AsyncTask<Void, Void, List<EventMO>>() {
@Override
protected List<EventMO> doInBackground(Void... arg0) {
eventMOs = gson.fromJson(eventDelegates.getAllEventFromUser(userMO, context), new TypeToken<List<EventMO>>() {
}.getType());
invitationMOs = gson.fromJson(eventDelegates.getAllEventForUser(userMO, context), new TypeToken<List<EventMO>>() {
}.getType());
List<EventMO> groupEventMOList = new ArrayList<>();
for (EventMO eventMO : eventMOs) {
groupEventMOList.add(eventMO);
}
for (EventMO eventMO : invitationMOs) {
groupEventMOList.add(eventMO);
}
return groupEventMOList;
}
@Override
protected void onPostExecute(List<EventMO> groupEventMOList) {
groupEventMoList = groupEventMOList;
prgDialog.dismiss();
DatabaseHelper dbHelper = new DatabaseHelper(context);
//long totalInsertion = dbHelper.insertUserRelationTable(userMOs);
//Toast.makeText(context, "total userMos size " + userMOs.size() + "total db insertion size " + totalInsertion, Toast.LENGTH_LONG).show();
GroupEventView = (ListView) view.findViewById(R.id.chat_list_view);
chatDisplayAdapter = new ChatDisplayAdapter();
GroupEventView.setAdapter(chatDisplayAdapter);
GroupEventView.setItemsCanFocus(true);
GroupEventView.setTextFilterEnabled(true);
GroupEventView.setOnItemClickListener(GroupEventView.getOnItemClickListener());
}
}.execute(null, null, null);
return view;
}
private class ChatDisplayAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public ChatDisplayAdapter() {
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return groupEventMoList.size();
}
@Override
public Object getItem(int position) {
return groupEventMoList.get(position);
}
@Override
public long getItemId(int id) {
// for sqllite management
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.chatwindow, null);
convertView.setClickable(true);
convertView.setFocusable(true);
chatTitle = (TextView) convertView.findViewById(R.id.chat_title);
chatPlace = (TextView) convertView.findViewById(R.id.event_place);
chatDate = (TextView) convertView.findViewById(R.id.event_date);
chatPlace.setTextColor(getResources().getColor(R.color.black));
chatDate.setTextColor(getResources().getColor(R.color.black));
chatTitle.setTextColor(getResources().getColor(R.color.black));
chatPlace.setText(groupEventMoList.get(position).getPlace());
String actualDate = groupEventMoList.get(position).getEventDate();
//chatDate.setText(groupEventMoList.get(position).getEventDate());
try {
//date format changed here
Date formatDate = new SimpleDateFormat("yyyy-MM-dd").parse(actualDate);
dateResult = new SimpleDateFormat("dd-MM-yyyy").format(formatDate);
} catch (ParseException e) {
e.printStackTrace();
}
chatDate.setText(dateResult);
chatTitle.setText(groupEventMoList.get(position).getText());
convertView.setTag(position);
View v = convertView.findViewById(R.id.chat_window_single);
v.getRootView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("position", v.getTag().toString());
Intent groupAct = new Intent(context, GroupChatActivity.class);
groupAct.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
groupAct.putExtra("eventMo", groupEventMoList.get(Integer.parseInt(v.getTag().toString())));
startActivity(groupAct);
}
});
}
return convertView;
}
}
}