如何在android的listview中显示选定的griditem值

如何在android的listview中显示选定的griditem值,android,listview,gridview,Android,Listview,Gridview,我正在开发一个应用程序,其中将有一组来自数据库的值,如采集、加载、传输等,甚至用户可以在其中添加新类别。这些项目显示在网格视图中,效果良好。当我从网格中选择特定项目时,它应该显示在列表视图中(如果我选择Purching,则意味着它应将内容显示为标题、树的编号及其值) 主要活动: public class GridActivity extends AppCompatActivity{ GridView gv; ListView listview; ArrayList<CustomizedCh

我正在开发一个应用程序,其中将有一组来自数据库的值,如采集、加载、传输等,甚至用户可以在其中添加新类别。这些项目显示在网格视图中,效果良好。当我从网格中选择特定项目时,它应该显示在列表视图中(如果我选择Purching,则意味着它应将内容显示为标题、树的编号及其值)

主要活动:

public class GridActivity extends AppCompatActivity{
GridView gv;
ListView listview;
ArrayList<CustomizedCharge>listcharges;
AlertDialog alert;
String totalamount;
LinearLayout eview;
private List<CustomizedCharge> listactivitycharge;
 FetchlistData listadapter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.otherchargesscreen);

    gv=(GridView) findViewById(R.id.gridview1);
    listview=(ListView) findViewById(R.id.list_view);
    eview=(LinearLayout)findViewById(R.id.empty);
    DatabaseHandlerOtherchgs databaseHandlerOtherchgs=new DatabaseHandlerOtherchgs(getApplicationContext());
    ArrayList<OtherChargesType> listet = new ArrayList<OtherChargesType>();

    Resources res = getResources();
    Drawable drawable = res.getDrawable(R.drawable.p);
    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] bitMapData = stream.toByteArray();

    Drawable loading = res.getDrawable(R.drawable.l);
    Bitmap bitmaploading = ((BitmapDrawable)loading).getBitmap();
    ByteArrayOutputStream streamloading = new ByteArrayOutputStream();
    bitmaploading.compress(Bitmap.CompressFormat.PNG, 100, streamloading);
    byte[] bitMaploading = streamloading.toByteArray();

    Drawable addnew = res.getDrawable(R.mipmap.add);
    Bitmap bitmapaddnew = ((BitmapDrawable)addnew).getBitmap();
    ByteArrayOutputStream streamadd = new ByteArrayOutputStream();
    bitmapaddnew.compress(Bitmap.CompressFormat.PNG, 100, streamadd);
    byte[] bitMapaddnew = streamadd.toByteArray();

    listet=databaseHandlerOtherchgs.getAllproducttitle();
    listet.add(new OtherChargesType("Plucking",bitMapData));
    listet.add(new OtherChargesType("Loading",bitMaploading));
    listet.add(new OtherChargesType("Add New",bitMapaddnew));

    final OtherChargesGridAdapter adapter = new OtherChargesGridAdapter(GridActivity.this, listet);
           gv.setAdapter(adapter);
    listcharges=new ArrayList<CustomizedCharge>();
    listcharges.add(new CustomizedCharge(bitMapData, "Loading", "No of Loads", "0", "Cost per Load", "0", "0"));

    listadapter=new FetchlistData(GridActivity.this,listcharges);
    if(listadapter!=null) {
        if (listadapter.getCount() > 0) {
            eview.setVisibility(View.INVISIBLE);
            Intent i = getIntent();
            String textreceived = i.getStringExtra("Selectedname");
            if (textreceived.startsWith("Plucking")) {

                listcharges.add(new CustomizedCharge(bitMapData, "Loading", "No of Loads", "0", "Cost per Load", "0", "0"));
                listadapter=new FetchlistData(GridActivity.this,listcharges);
             } else if (textreceived.startsWith("Loading")) {
                listcharges.add(new CustomizedCharge(bitMapData, "Loading", "No of Loads", "0", "Cost per Load", "0", "0"));
            } else {
               listcharges= databaseHandlerOtherchgs.getAllLabels();
            }

            listview.setAdapter(listadapter);
        }else{
            listview.setEmptyView(eview);
        }

    }

}

Grid Adapter:


public class OtherChargesGridAdapter extends BaseAdapter {
Context context;
String totalamount;
AlertDialog alert;
private Activity activity;
byte[] bitMapData;
private LayoutInflater inflater;
private List<OtherChargesType> otherchargestypes;
private List<CustomizedCharge> listactivitycharge;

public OtherChargesGridAdapter(Activity activity, List<OtherChargesType> otherchargestypes) {
    this.activity = activity;
    this.otherchargestypes = otherchargestypes;
}

@Override
public int getCount() {
    return otherchargestypes.size();
}

@Override
public Object getItem(int i) {
    return otherchargestypes.get(i);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertview, ViewGroup parent) {

    if (inflater == null) {
        inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    if (convertview == null) {
        convertview = inflater.inflate(R.layout.otherchargesgriditem, null);
    }
    OtherChargesType m = otherchargestypes.get(position);
    byte[] outImage = m.getImage();
    ByteArrayInputStream imageStream = new ByteArrayInputStream(outImage);
    final Bitmap theImage = BitmapFactory.decodeStream(imageStream);
    ImageView otherimages = (ImageView) convertview.findViewById(R.id.imageView1);

    final TextView typename = (TextView) convertview.findViewById(R.id.textView1);

    // getting movie data for the row


    typename.setText(m.getTypename());
    otherimages.setImageBitmap(theImage);
    convertview.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
           if (typename.getText().toString().startsWith("Add New")) {
                final LayoutInflater layoutInflater = LayoutInflater.from(activity);
                final View promptView = layoutInflater.inflate(R.layout.activity_addnewcharge, null);
                final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
                alertDialogBuilder.setView(promptView);
                alertDialogBuilder.setCancelable(true);

                final TextInputLayout txipagetitle = (TextInputLayout) promptView.findViewById(R.id.inputpagetitle);
                final TextInputLayout txiquantitytitle = (TextInputLayout) promptView.findViewById(R.id.inputqunatitytitle);
                final TextInputLayout txiquantity = (TextInputLayout) promptView.findViewById(R.id.inputquantity);
                final TextInputLayout txiratetitle = (TextInputLayout) promptView.findViewById(R.id.inputratetitle);
                final TextInputLayout txirate = (TextInputLayout) promptView.findViewById(R.id.inputrate);
                final EditText edtpagetitle = (EditText) promptView.findViewById(R.id.edtpagetitle);
                final EditText edtquantitytitle = (EditText) promptView.findViewById(R.id.edtquantitytitle);
                final EditText edtquantity = (EditText) promptView.findViewById(R.id.edtquantity);
                final EditText edtratetitle = (EditText) promptView.findViewById(R.id.edtratetitle);
                final EditText edtrate = (EditText) promptView.findViewById(R.id.edtrate);
                final TextView tvtotal = (TextView) promptView.findViewById(R.id.tvtotalamount);
                final ImageView savedata = (ImageView) promptView.findViewById(R.id.btn_save);
                edtquantity.setText("0.0");
                edtrate.setText("0.0");
                double one = Double.parseDouble(edtquantity.getText().toString());
                double two = Double.parseDouble(edtrate.getText().toString());
                double three = (one * two);
                totalamount = String.valueOf(three);
                tvtotal.setText(totalamount);
                txipagetitle.setError(null);
                txiquantitytitle.setError(null);
                txiquantity.setError(null);
                txiratetitle.setError(null);
                txirate.setError(null);
                edtrate.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                    @Override
                    public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                        double one = Double.parseDouble(edtquantity.getText().toString());
                        double two = Double.parseDouble(edtrate.getText().toString());
                        double three = (one * two);
                        totalamount = String.valueOf(three);
                        tvtotal.setText(totalamount);
                        return false;
                    }
                });
                savedata.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        DatabaseHandlerOtherchgs databaseHandlerOtherchgs = new DatabaseHandlerOtherchgs(activity);
                        if (edtpagetitle.getText().toString().isEmpty() & edtquantitytitle.getText().toString().isEmpty() & edtquantity.getText().toString().isEmpty() & edtratetitle.getText().toString().isEmpty() & edtrate.getText().toString().isEmpty()) {
                            txipagetitle.setError("Enter Title");
                            txiquantitytitle.setError("Enter Quantity Title");
                            txiquantity.setError("Enter Quantity");
                            txiratetitle.setError("Enter Rate Title");
                            txirate.setError("Enter Rate");

                        } else {
                            txipagetitle.setError(null);
                            txiquantitytitle.setError(null);
                            txiquantity.setError(null);
                            txiratetitle.setError(null);
                            txirate.setError(null);
                            String pagetitle = edtpagetitle.getText().toString();
                            String quantitytitle = edtquantitytitle.getText().toString();
                            String quantity = edtquantity.getText().toString();
                            String ratetitle = edtratetitle.getText().toString();
                            String rate = edtrate.getText().toString();
                            String tot = tvtotal.getText().toString();

                            if (edtpagetitle.getText().toString().startsWith("A") | edtpagetitle.getText().toString().startsWith("a")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.a);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("B") | edtpagetitle.getText().toString().startsWith("b")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.b);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();


                            } else if (edtpagetitle.getText().toString().startsWith("C") | edtpagetitle.getText().toString().startsWith("c")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.c);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();


                            } else if (edtpagetitle.getText().toString().startsWith("D") | edtpagetitle.getText().toString().startsWith("d")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.d);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("E") | edtpagetitle.getText().toString().startsWith("e")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.e);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();


                            } else if (edtpagetitle.getText().toString().startsWith("F") | edtpagetitle.getText().toString().startsWith("f")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.f);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();

                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();


                            } else if (edtpagetitle.getText().toString().startsWith("G") | edtpagetitle.getText().toString().startsWith("g")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.g);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();


                            } else if (edtpagetitle.getText().toString().startsWith("H") | edtpagetitle.getText().toString().startsWith("h")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.h);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();


                            } else if (edtpagetitle.getText().toString().startsWith("I") | edtpagetitle.getText().toString().startsWith("i")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.i);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("J") | edtpagetitle.getText().toString().startsWith("j")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.j);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();


                            } else if (edtpagetitle.getText().toString().startsWith("K") | edtpagetitle.getText().toString().startsWith("k")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.k);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();


                            } else if (edtpagetitle.getText().toString().startsWith("L") | edtpagetitle.getText().toString().startsWith("l")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.l);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();


                            } else if (edtpagetitle.getText().toString().startsWith("M") | edtpagetitle.getText().toString().startsWith("m")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.m);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("N") | edtpagetitle.getText().toString().startsWith("n")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.n);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("O") | edtpagetitle.getText().toString().startsWith("o")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.o);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("P") | edtpagetitle.getText().toString().startsWith("p")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.p);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("Q") | edtpagetitle.getText().toString().startsWith("q")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.q);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("R") | edtpagetitle.getText().toString().startsWith("r")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.r);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("S") | edtpagetitle.getText().toString().startsWith("s")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.s);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("T") | edtpagetitle.getText().toString().startsWith("t")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.t);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("U") | edtpagetitle.getText().toString().startsWith("u")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.u);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("V") | edtpagetitle.getText().toString().startsWith("v")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.v);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("W") | edtpagetitle.getText().toString().startsWith("w")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.w);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("X") | edtpagetitle.getText().toString().startsWith("x")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.x);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("Y") | edtpagetitle.getText().toString().startsWith("y")) {
                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.y);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            } else if (edtpagetitle.getText().toString().startsWith("Z") | edtpagetitle.getText().toString().startsWith("z")) {

                                Resources res = activity.getResources();
                                Drawable drawable = res.getDrawable(R.drawable.z);
                                Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
                                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                                bitMapData = stream.toByteArray();

                            }
                            databaseHandlerOtherchgs.insertLabel(bitMapData, pagetitle, quantitytitle, quantity, ratetitle, rate, tot);
                            alert.dismiss();
                            Intent k=activity.getIntent();
                            activity.startActivity(k);

                        }
                    }
                });

                alert = alertDialogBuilder.create();
                alert.show();

           }else if (typename.getText().toString().startsWith("Plucking")) {
               Intent i= new Intent(activity,GridActivity.class);
               i.putExtra("Selectedname","Plucking");
               activity.startActivity(i);

            } else if (typename.getText().toString().startsWith("Loading")) {
               Intent i= new Intent(activity,GridActivity.class);
               i.putExtra("Selectedname","Loading");
               activity.startActivity(i);

            }else {
               String s=typename.getText().toString();
               Intent i= new Intent(activity,GridActivity.class);
               i.putExtra("Selectedname",s);
               activity.startActivity(i);

           }


        }


    });
    return convertview;
}
公共类GridActivity扩展了AppCompatActivity{
GridView gv;
列表视图列表视图;
诉讼费用;
警报对话框警报;
字符串总数;
线性布局回顾;
私有列表listactivitycharge;
获取列表数据列表适配器;
@凌驾
创建时受保护的void(@Nullable Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.otherchargesscreen);
gv=(GridView)findViewById(R.id.gridview1);
listview=(listview)findViewById(R.id.list\u视图);
eview=(LinearLayout)findViewById(R.id.empty);
DatabaseHandlerOtherchgs DatabaseHandlerOtherchgs=新的DatabaseHandlerOtherchgs(getApplicationContext());
ArrayList ListT=新的ArrayList();
Resources res=getResources();
可提取可提取=可提取(R.Drawable.p);
位图位图=((BitmapDrawable)drawable.getBitmap();
ByteArrayOutputStream=新建ByteArrayOutputStream();
compress(bitmap.CompressFormat.PNG,100,流);
字节[]bitMapData=stream.toByteArray();
可拉深载荷=可拉深(R.Drawable.l);
位图位图位图加载=((BitmapDrawable)加载).getBitmap();
ByteArrayOutputStream加载=新建ByteArrayOutputStream();
bitmaploading.compress(Bitmap.CompressFormat.PNG,100,streamloading);
字节[]bitMaploading=streamloading.toByteArray();
Drawable addnew=res.getDrawable(R.mipmap.add);
位图bitmapaddnew=((BitmapDrawable)addnew).getBitmap();
ByteArrayOutputStream添加=新建ByteArrayOutputStream();
bitmapaddnew.compress(Bitmap.CompressFormat.PNG,100,streamadd);
字节[]bitMapaddnew=streamadd.toByteArray();
liset=databaseHandlerOtherchgs.getAllproducttitle();
添加(新的OtherChargesType(“Pucking”,bitMapData));
添加(新的OtherChargesType(“加载”,bitMaploading));
添加(新的其他费用类型(“添加新”,bitMapaddnew));
最终OtherChargesGridAdapter=新的OtherChargesGridAdapter(GridActivity.this,ListT);
gv.设置适配器(适配器);
listcharges=新的ArrayList();
添加(新的定制费用(位图数据,“加载”、“加载次数”、“0”、“每加载成本”、“0”、“0”));
listadapter=新的FetchlistData(GridActivity.this,listcharges);
if(listadapter!=null){
如果(listadapter.getCount()>0){
eview.setVisibility(View.INVISIBLE);
Intent i=getIntent();
String textreceived=i.getStringExtra(“Selectedname”);
if(textreceived.startsWith(“拨动”)){
添加(新的定制费用(位图数据,“加载”、“加载次数”、“0”、“每加载成本”、“0”、“0”));
listadapter=新的FetchlistData(GridActivity.this,listcharges);
}else if(textreceived.startsWith(“加载”)){
添加(新的定制费用(位图数据,“加载”、“加载次数”、“0”、“每加载成本”、“0”、“0”));
}否则{
listcharges=databaseHandlerOtherchgs.getAllLabels();
}
setAdapter(listadapter);
}否则{
setEmptyView(eview);
}
}
}
网格适配器:
公共类OtherChargesGridAdapter扩展BaseAdapter{
语境;
字符串总数;
警报对话框警报;
私人活动;
字节[]位图数据;
私人充气机;
私人列表其他收费项目;
私有列表listactivitycharge;
公共其他费用ridadapter(活动,列出其他费用类型){
这个。活动=活动;
this.otherchargestypes=otherchargestypes;
}
@凌驾
public int getCount(){
返回其他ChargeStypes.size();
}
@凌驾
公共对象getItem(int i){
返回其他Chargestypes.get(i);
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
如果(充气器==null){
充气器=(充气器)活动
.getSystemService(上下文布局\充气机\服务);
}
if(convertview==null){
convertview=充气机。充气(R.layout.otherchargesgriditem,null);
}
OtherChargesType m=OtherChargesType.get(位置);
字节[]outImage=m.getImage();
ByteArrayInputStream imageStream=新的ByteArrayInputStream(outImage);
最终位图theImage=BitmapFactory.decodeStream(图像流);
ImageView其他图像=(ImageView)convertview.findViewById(R.id.imageView1);
final TextView typename=(TextView)convertview.findViewById(R.id.textView1);
//正在获取行的电影数据
setText(m.getTypename());
设置图像位图(图像);
convertview.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
if(typename.getText().toString().startsWith(“添加新”)){
最终LayoutInflater LayoutInflater=LayoutInflater.from(活动);
最终视图promptView=LayoutFlater.充气(R.layout.activity\u addnewcharge,null);
最终AlertDialog.Builder alertDialogBuilder=新建AlertDialog.Builder(活动);
alertDialogBuilder.setView(promptView);
alertDialogBuilder.setCancelable(true);
最终文本输入布局txipagetitle=(文本输入布局)promptView.findViewById(R.id.inputpagetitle);
最终TextInputLayout txiquantitytitle=(TextInputLayout)promptView.findViewById(R.id.InputQuentityTitle);
   AdapterView.OnItemSelectedListener gridSelectedListener= new AdapterView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
     //ListView Title 
     title.setText(gridItemsList.get(position).getTitle());
     //ListView Content
     content.setText(gridItemsList.get(position).content());

    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }
};
yourGridView.setOnItemSelectedListener(gridSelectedListener);