1
我有一個問題,我想在彈出窗口中顯示自定義GridView
圖像和文本。圖像來自webservice,但我的適配器無法顯示GridView
項目。我不知道爲什麼?請給我建議任何解決方案。在彈出窗口中顯示網格視圖
代碼:
private void showSearchPopUp()
{
View view = LayoutInflater.from(VideoActivity.this).inflate(R.layout.search_pop_up, null);
PopupWindow popupWindow = new PopupWindow(
view,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
popupWindow.setWidth(1230);
popupWindow.setHeight(800);
//popupWindow.showAtLocation(imgSearch, Gravity.LEFT|Gravity.TOP, 0, -30);
popupWindow.showAsDropDown(relHeader, 0, -30);
LinearLayout llSearchAlpha = (LinearLayout)view.findViewById(R.id.llSearchAlpha);
TextView tvAlpha;
for(int i=0;i<alpha.length;i++)
{
tvAlpha = new TextView(VideoActivity.this);
tvAlpha.setTextColor(Color.WHITE);
tvAlpha.setText(alpha[i]);
tvAlpha.setTextSize(15);
tvAlpha.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 1f));
llSearchAlpha.addView(tvAlpha);
}
getActors();
}
private void getActors()
{
View view = LayoutInflater.from(VideoActivity.this).inflate(R.layout.search_pop_up, null);
final GridView grid = (GridView)view.findViewById(R.id.gvSearch);
grid.setWillNotDraw(false);
grid.setFocusableInTouchMode(true);
grid.setClickable(true);
new Thread(new Runnable() {
@Override
public void run() {
actors = Server.getSearchActor();
runOnUiThread(new Runnable() {
@Override
public void run() {
SearchActorCategoryLazyAdapter searchAdapter = new SearchActorCategoryLazyAdapter(VideoActivity.this, actors);
grid.setAdapter(searchAdapter);
}
});
}
}).start();
}
public class SearchActorCategoryLazyAdapter extends BaseAdapter
{
Context _contextObj;
List<Actor> listActor;
private LayoutInflater inflater;
private ImageLoader imageLoader;
public SearchActorCategoryLazyAdapter(Context context, List<Actor> listActor)
{
_contextObj = context;
this.listActor = listActor;
this.inflater = (LayoutInflater) _contextObj.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.imageLoader = new ImageLoader(_contextObj.getApplicationContext());
}
@Override
public int getCount()
{
return listActor.size();
}
@Override
public Object getItem(int position)
{
return null;
}
@Override
public long getItemId(int position)
{
return 0;
}
static class ViewHolder
{
TextView tvActorName;
ImageView imgSearch;
int position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolderObj = new ViewHolder();
LayoutInflater inflaterObj = (LayoutInflater)_contextObj.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = (View)inflaterObj.inflate(R.layout.search_griditem, parent,true);
}
viewHolderObj.tvActorName = (TextView)convertView.findViewById(R.id.tvSearchName);
viewHolderObj.imgSearch = (ImageView)convertView.findViewById(R.id.imgSearch);
viewHolderObj.tvActorName.setText(listActor.get(position).getActor_name());
Activity activity = (Activity)_contextObj;
imageLoader.displayImage(listActor.get(position).getActor_image(), activity, viewHolderObj.imgSearch);
return convertView;
}
}
在此先感謝。