2
public class ExploreScreenActivity extends Activity implements OnClickListener, OnItemClickListener,IServerResponse{
private ImageButton _refreshBtn=null;
private ImageButton _searchBtn=null;
private Button _cancelBtn=null;
private EditText _searchText=null;
public TextWatcher filterTextWatcher;
private TextView _exploreTxt=null;
private LinearLayout _search_all_layout=null;
private ImageButton _allSearchBtn=null;
private ImageButton _brandsSearchBtn=null;
private ImageButton _itemsSearchBtn=null;
private ImageButton _peopleSearchBtn=null;
private SharedPreferences _sPrefs=null;
public ArrayList<Object> _itemList=null;
private ArrayList<Object>_brandlist=null;
private ArrayList<Object>_alluserlist=null;
private ArrayList<Object>_peoplelist=null;
private ArrayList<Object>_defaultlist=null;
private String type=null;;
private String searchString=null;;
private GridView _explorGridView=null;
private GridSearchNewAdapter adapter=null;
private GridBrandadapter brandadapter=null;
private GridAllUserAdapter alladapter=null;
private GridItemAdapter itemadapter=null;
private GridUserAdapter useradapter=null;
private Defaultadapter adapter11=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_explorscreen);
_sPrefs=getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
_itemList = new ArrayList<Object>();
_brandlist=new ArrayList<Object>();
_alluserlist=new ArrayList<Object>();
_peoplelist=new ArrayList<Object>();
_defaultlist=new ArrayList<Object>();
_refreshBtn=(ImageButton)findViewById(R.id.refresh_btn);
_refreshBtn.setOnClickListener(this);
_search_all_layout=(LinearLayout)findViewById(R.id.search_all_layout);
_searchBtn=(ImageButton)findViewById(R.id.search_btn);
_searchBtn.setOnClickListener(this);
_searchText=(EditText)findViewById(R.id.search_edtTxt);
_searchText.setOnClickListener(this);
_cancelBtn=(Button)findViewById(R.id.cancel_btn);
_cancelBtn.setOnClickListener(this);
_explorGridView=(GridView)findViewById(R.id.explor_gridView);
_exploreTxt=(TextView)findViewById(R.id.explor_textView);
_allSearchBtn=(ImageButton)findViewById(R.id.all_search_btn);
_allSearchBtn.setOnClickListener(this);
_brandsSearchBtn=(ImageButton)findViewById(R.id.brands_search_btn);
_brandsSearchBtn.setOnClickListener(this);
_itemsSearchBtn=(ImageButton)findViewById(R.id.items_search_btn);
_itemsSearchBtn.setOnClickListener(this);
_peopleSearchBtn=(ImageButton)findViewById(R.id.people_search_btn);
_peopleSearchBtn.setOnClickListener(this);
type= _searchText.getText().toString();
searchString=_searchText.getText().toString();
getSearch(type,searchString);
_explorGridView.setOnItemClickListener(this);
_searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
Intent intent=new Intent(ExploreScreenActivity.this, FeedSelectedActivity.class);
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
parentActivity.startChildActivity("feedselected", intent);
return true;
}
return false;
}
});
onResume();
{
super.onResume();
getSearch(type, searchString);
}
_searchText.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
searchString = _searchText.getText().toString().toLowerCase(Locale.getDefault());
searchString =s.toString();
getSearch(type,searchString);
alladapter.filter(searchString);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
});
}
@Override
public void onClick(View v) {
TabGroupActivity parentActivity=(TabGroupActivity)getParent();
Intent intent=null;
switch (v.getId()) {
case R.id.refresh_btn:
break;
case R.id.search_btn:
_searchText.setText("");
intent=new Intent(this, FeedSelectedActivity.class);
parentActivity.startChildActivity("feedselect", intent);
break;
case R.id.cancel_btn:
_exploreTxt.setVisibility(View.VISIBLE);
_searchBtn.setVisibility(View.VISIBLE);
_search_all_layout.setVisibility(View.GONE);
_cancelBtn.setVisibility(View.GONE);
_searchText.setText("");
// _explorGridView.setAdapter(mAdapter);
break;
case R.id.search_edtTxt:
_exploreTxt.setVisibility(View.GONE);
_searchBtn.setVisibility(View.GONE);
_cancelBtn.setVisibility(View.VISIBLE);
_search_all_layout.setVisibility(View.VISIBLE);
break;
case R.id.all_search_btn:
_brandsSearchBtn.setBackgroundResource(R.drawable.brand_deselected);
_itemsSearchBtn.setBackgroundResource(R.drawable.items_deselected);
_peopleSearchBtn.setBackgroundResource(R.drawable.people_deselected);
_allSearchBtn.setBackgroundResource(R.drawable.all_selected);
type="all";
getSearch(type, searchString);
break;
case R.id.brands_search_btn:
_brandsSearchBtn.setBackgroundResource(R.drawable.brand_selected);
_itemsSearchBtn.setBackgroundResource(R.drawable.items_deselected);
_peopleSearchBtn.setBackgroundResource(R.drawable.people_deselected);
_allSearchBtn.setBackgroundResource(R.drawable.all_deselected);
type="brand";
getSearch(type,searchString);
break;
case R.id.items_search_btn:
_brandsSearchBtn.setBackgroundResource(R.drawable.brand_deselected);
_itemsSearchBtn.setBackgroundResource(R.drawable.items_selected);
_peopleSearchBtn.setBackgroundResource(R.drawable.people_deselected);
_allSearchBtn.setBackgroundResource(R.drawable.all_deselected);
type="item";
getSearch(type,searchString);
break;
case R.id.people_search_btn:
_brandsSearchBtn.setBackgroundResource(R.drawable.brand_deselected);
_itemsSearchBtn.setBackgroundResource(R.drawable.items_deselected);
_peopleSearchBtn.setBackgroundResource(R.drawable.people_selected);
_allSearchBtn.setBackgroundResource(R.drawable.all_deselected);
type="user";
getSearch(type,searchString);
break;
default:
break;
}
}
private void getSearch(String type,String searchString) {
if (NetworkAvailablity.checkNetworkStatus(ExploreScreenActivity.this)) {
ArrayList<NameValuePair> requestParaList = new ArrayList<NameValuePair>();
requestParaList.add(new BasicNameValuePair("type", _sPrefs.getString("type",type)));
requestParaList.add(new BasicNameValuePair("searchstring", _sPrefs.getString("searchstring",searchString)));
// requestParaList.add(new BasicNameValuePair("type", type));
// requestParaList.add(new BasicNameValuePair("searchstring",searchString));
WebServiceCommunicator.getInstance().registerForServerResponse((IServerResponse) ExploreScreenActivity.this);
WebServiceCommunicator.getInstance().callGetAppWebService(false,
this,
WSConstant.getUrl(WSConstant.METHOD_SEARCH),
ExploreScreenActivity.this, WSConstant.PID_SEARCH, false,
requestParaList);
}
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Intent intent=new Intent(this, FeedSelectedActivity.class);
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
parentActivity.startChildActivity("feedselected", intent);
//startActivity(intent);
}
private Handler _handler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.arg2) {
case WSConstant.PID_SEARCH:
getJsonResponse(msg.obj.toString(), msg.arg2);
break;
default:
break;
}
}
};
private void getJsonResponse(String response, int arg2) {
JSONObject jObject=null;
try {
jObject = new JSONObject(response);
JSONArray list = jObject.getJSONArray("posts");
for (int i = 0; i < list.length(); i++) {
JSONObject element = list.getJSONObject(i);
if (type.equalsIgnoreCase("all")) {
AllBean bean= new AllBean();
bean.setid(element.getString("id"));
bean.setfullname(element.getString("fullname"));
bean.setusername(element.getString("username"));
bean.setprofile_photo(element.getString("profile_photo"));
bean.setprofile_type(element.getString("profile_type"));
bean.setprofile(element.getString("profile"));
// _alluserlist.clear();
_alluserlist.add(bean);
}
if (_alluserlist.size()!=0) {
alladapter=new GridAllUserAdapter(ExploreScreenActivity.this, _alluserlist);
_explorGridView.setAdapter(alladapter);
}
else if (type.equalsIgnoreCase("brand")) {
BrandBean bean= new BrandBean();
bean.setbrand_id(element.getString("brand_id"));
bean.setbrand_name(element.getString("brand_name"));
bean.setbrand_photo(element.getString("brand_photo"));
_brandlist.add(bean);
}
if (_brandlist.size()!=0) {
brandadapter=new GridBrandadapter(ExploreScreenActivity.this, _brandlist);
_explorGridView.setAdapter(brandadapter);
}
else if (type.equalsIgnoreCase("item")) {
ItemBean bean= new ItemBean();
bean.setitem_id(element.getString("item_id"));
bean.setitem_name(element.getString("item_name"));
bean.setitem_photo(element.getString("item_photo"));
_itemList.add(bean);
}
if (_itemList.size()!=0) {
itemadapter=new GridItemAdapter(ExploreScreenActivity.this, _itemList);
_explorGridView.setAdapter(itemadapter);
}
else if (type.equalsIgnoreCase("user")) {
UserBean bean= new UserBean();
bean.setid(element.getString("id"));
bean.setfullname(element.getString("fullname"));
bean.setusername(element.getString("username"));
bean.setprofile_photo(element.getString("profile_photo"));
_peoplelist.add(bean);
}
if (_peoplelist.size()!=0) {
useradapter=new GridUserAdapter(ExploreScreenActivity.this, _peoplelist);
_explorGridView.setAdapter(useradapter);
}
else {
DefaultBean bean=new DefaultBean();
bean.setmedia_id(element.getString("media_id"));
bean.setthumbnail_image(element.getString("thumbnail_image"));
bean.setmedia_owner(element.getString("media_owner"));
_defaultlist.add(bean);
}
if (_defaultlist.size()!=0) {
adapter11=new Defaultadapter(ExploreScreenActivity.this, _defaultlist);
adapter11.notifyDataSetChanged();
_explorGridView.setAdapter(adapter11);
}
}
}
catch (Exception e) {
// TODO: handle exception
}
}
@Override
public void serverResponse(String response, int processid) {
// TODO Auto-generated method stub
Message msg = new Message();
msg.obj = response;
msg.arg2 = processid;
_handler.sendMessage(msg);
}
}
我正在使用gridview来显示我的项目,图片来自服务器,当我的活动出现在我的这个活动中时,我已经调用了一个webservice,当时所有的值都显示出来。 2在我的gridview中,我有4个按钮,当我克服任何按钮时,我的另一个webservice调用,现在的问题是我的新griditems没有正确显示,他们只是2或3,我做什么请帮助我.. ,我从这两天开始搜索..谢谢你。android my gridview data没有显示所有来自服务器的项目?