CERCA
PER MODELLO
FullScreen Chatbox! :)

Utente del giorno: bluflight13 con ben 40 Thanks ricevuti nelle ultime 24 ore
Utente della settimana: bluflight13 con ben 106 Thanks ricevuti negli ultimi sette giorni
Utente del mese: Pierdebeer con ben 421 Thanks ricevuti nell'ultimo mese

Visualizzazione dei risultati da 1 a 1 su 1
Discussione:

Come inserire una activity in un textview

  1. #1
    Androidiano
    Registrato dal
    Apr 2011
    LocalitÓ
    Bologna
    Messaggi
    167
    Smartphone
    Huawei Ascend Y300
    Thanks
    6
    Thanked 58 Times in 19 Posts
    Predefinito

    Come inserire una activity in un textview

    Salve, io ho questo codice


    Java:
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;


    import android.app.ExpandableListActivity;
    import android.content.Context;
    import android.content.res.Resources;
    import android.graphics.drawable.Drawable;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ExpandableListAdapter;
    import android.widget.ImageView;
    import android.widget.SimpleExpandableListAdapter;
    import android.widget.TextView;

    /**
    * Demonstrates expandable lists using a custom {...@link
    ExpandableListAdapter}
    * from {...@link BaseExpandableListAdapter}.
    */
    public class sedactivity extends ExpandableListActivity { ExpandableListAdapter mAdapter;


    private final static String NAME = "NAME";
    private final static String SURNAME = "SURNAME";
    private Resources res;
    private Drawable photo, photo2, photo3, photo4;
    private List<Drawable> albumCovers;


    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_main);

    // Create a List of Drawables to insert into the Expandable List
    // This can be completely dynamic
    res = this.getResources();
    photo = (Drawable) res.getDrawable(R.drawable.bosco);
    photo2 = (Drawable) res.getDrawable(R.drawable.albero);
    photo3 = (Drawable) res.getDrawable(R.drawable.bomba);
    photo4 = (Drawable) res.getDrawable(R.drawable.astronave);
    albumCovers = new ArrayList<Drawable>();
    albumCovers.add(photo);
    albumCovers.add(photo2);

    // The following code simply generates the Expandable Lists content (Strings)
    List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
    List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
    Map<String, String>


    //Lista A
    curGroupMap = new HashMap<String, String>();
    groupData.add(curGroupMap);

    curGroupMap.put(NAME, "A");
    curGroupMap.put(SURNAME, "(2 Foto)");



    List<Map<String, String>> children = new ArrayList<Map<String, String>>();
    Map<String, String> curChildMap = new HashMap<String, String>();
    children.add(curChildMap);


    curChildMap.put(NAME, "Albero");


    curChildMap = new HashMap<String, String>();
    children.add(curChildMap);

    curChildMap.put(NAME, "Astronave");

    curChildMap = new HashMap<String, String>();
    children.add(curChildMap);


    childData.add(children);


    //Lista B
    curGroupMap = new HashMap<String, String>();
    groupData.add(curGroupMap);


    curGroupMap.put(NAME, "B");
    curGroupMap.put(SURNAME, "(2 Foto)");

    children = new ArrayList<Map<String, String>>();

    curChildMap = new HashMap<String, String>();
    children.add(curChildMap);

    curChildMap.put(NAME, "Bosco");

    curChildMap = new HashMap<String, String>();
    children.add(curChildMap);

    curChildMap.put(NAME, "Bomba");

    curChildMap = new HashMap<String, String>();
    children.add(curChildMap);


    childData.add(children);


    //Lista C
    curGroupMap = new HashMap<String, String>();
    groupData.add(curGroupMap);


    curGroupMap.put(NAME, "C");
    curGroupMap.put(SURNAME, "(0 Foto)");

    children = new ArrayList<Map<String, String>>();


    childData.add(children);

    // Set up our adapter
    mAdapter = new MyExpandableListAdapter(
    this,
    groupData,
    R.layout.list_parent,
    new String[] { NAME, SURNAME },
    new int[] { R.id.rowText1, R.id.rowText2, R.id.photoAlbumImg },
    childData,
    R.layout.list_child,
    new String[] { NAME, SURNAME },
    new int[] { R.id.rowText1, R.id.photoAlbumImg }
    );
    setListAdapter(mAdapter);
    registerForContextMenu(getExpandableListView());
    }


    /**
    * A simple adapter which allows you to bind data to specific
    * Views defined within the layout of an Expandable Lists children
    * (Implement getGroupView() to define the layout of parents)
    */


    public class MyExpandableListAdapter extends SimpleExpandableListAdapter {

    private List<? extends List<? extends Map<String, ?>>> mChildData;
    private String[] mChildFrom;
    private int[] mChildTo;

    public MyExpandableListAdapter(Context context,
    List<? extends Map<String, ?>> groupData, int groupLayout,
    String[] groupFrom, int[] groupTo,
    List<? extends List<? extends Map<String, ?>>> childData,
    int childLayout, String[] childFrom, int[] childTo) {
    super(context, groupData, groupLayout, groupFrom, groupTo,
    childData, childLayout, childFrom, childTo);

    mChildData = childData;
    mChildFrom = childFrom;
    mChildTo = childTo;

    }

    public View getChildView(int groupPosition, int childPosition,
    boolean isLastChild, View convertView, ViewGroup parent) {

    View v;
    if (convertView == null) {
    v = newChildView(isLastChild, parent);
    } else {
    v = convertView;
    }
    bindView(v, mChildData.get(groupPosition).get(childPosition), mChildFrom,
    mChildTo, groupPosition, childPosition);
    return v;

    }

    // This method binds my data to the Views specified in the child xml layout
    private void bindView(View view, Map<String, ?> data, String[] from, int[] to, int groupPosition, int childPosition) {
    int len = to.length - 1;
    // Apply TextViews
    for (int i = 0; i < len; ++i) {
    TextView v = (TextView) view.findViewById(to[i]);
    if (v != null) {
    v.setText((String) data.get(from[i]));
    }
    // Apply ImageView
    ImageView imgV = (ImageView) view.findViewById(to[1]);
    if (imgV != null) {
    if(childPosition % 1 == 0) imgV.setImageDrawable(albumCovers.get(0));
    else imgV.setImageDrawable(albumCovers.get(1));
    }


    }

    }
    }
    }



    Come faccio a far partire l'activity riguardante "Albero" "Bomba" e via dicendo? Il file xml Ŕ composto da un imageview e a destra c'Ŕ un textview. Spero di essere stato comprensibile. Grazie.

  2.  

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •