如何在gridview中一起选择多个列

时间:2013-02-19 06:33:46

标签: android android-gridview

我正在开发一个应用程序,以在gridview中显示员工的详细信息... 它在gridview中正确地显示了它们,如id名称和地址,现在我想要当用户点击任何一个项目时,整行意味着应该一起选择5列,并根据id显示详细信息....我怎样才能选择多个gridview中的列一起??

片段类来显示网格

  public class Fragment2 extends Fragment {
public final static String EXTRA_MESSAGE = "com.MESSAGE";
DataManipulator dm;
private GridView gridView;
public static ArrayList<String> ArrayName = new ArrayList<String>();
List<Object[]> names2 = null;
String[] stg1;
String[] stgid;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    return inflater.inflate(R.layout.frag2, container, false);
}



@Override
public void onStart() {
    super.onStart();

    dm = new DataManipulator(getActivity());
    names2 = dm.selectAll();

    stg1 = new String[names2.size()];
    stgid = new String[names2.size()];
    int x = 0;

    for (Object[] name : names2) {

        stgid[x] = (String) name[0];
        stg1[x] = (String) name[0];     
        x++;
    }

    gridView = (GridView) getView().findViewById(R.id.gridView1);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_list_item_1, stg1);
    gridView.setAdapter(adapter);
    gridView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            String message = stgid[position];
            Intent intent = new Intent(getActivity().getBaseContext(),
                    Details.class);
                       //new activity to show details when selected according to id
            intent.putExtra(EXTRA_MESSAGE, message);
            getActivity().startActivity(intent);

        }
    });

}

  }

DataManipulator 类中的方法选择详细信息 -

  public List<Object[]> selectAll() {

    List<Object[]> list = new ArrayList<Object[]>();
    Cursor cursor = db.query(TABLE_NAME, new String[] { "id", "name",
            "number", "skypeId", "address" }, null, null, null, null,
            "name asc");

    int x = 0;
    if (cursor.moveToFirst()) {
        do {
            Object[] b0 = new String[] { cursor.getString(0)};
            list.add(b0);
            Object[] b1 = new String[] { cursor.getString(1)};
            list.add(b1);
            Object[] b2 = new String[] { cursor.getString(2)};
            list.add(b2);
            Object[] b3 = new String[] { cursor.getString(3)};
            list.add(b3);
            Object[] b4 = new String[] { cursor.getString(4)};
            list.add(b4);



            x = x + 1;
        } while (cursor.moveToNext());
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    cursor.close();

    return list;
}

0 个答案:

没有答案