How I can Contains a listActivity class in a activity class?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How I can Contains a listActivity class in a activity class?

Postby Jimmy Malibu » Fri Jul 25, 2008 8:25 pm

Hallo!
I need a little help. I have lots of sampled but it doesn't work. Perhaps anyone can help me.
I have an activity class (Konsole) and an listActivity class (List5) and I'd like the list contain in the activity class.
Can anyone help me? :(

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Konsole extends Activity {
  2.  
  3.    
  4.  
  5. List5 liste = new List5();
  6.  
  7.     Button initialiseButton; Button startButton; Button stopButton; Button destroyButton;
  8.  
  9.     Button loadButton; Button refreshButton; Button uninstallButton; Button infoButton;
  10.  
  11.    
  12.  
  13.     @Override
  14.  
  15.     public void onCreate(Bundle icicle) {
  16.  
  17.         super.onCreate(icicle);
  18.  
  19.        
  20.  
  21.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  22.  
  23.             //setContentView(R.layout.main);
  24.  
  25.         setContentView(R.layout.eingabefeld);
  26.  
  27.             //liste.msetListAdapter();
  28.  
  29.              
  30.  
  31.         initialiseButton = (Button)findViewById(R.id.get1);
  32.  
  33.         //initialiseButton.setOnClickListener(initialiseListener);
  34.  
  35.         initialiseButton.setEnabled(false);
  36.  
  37.        
  38.  
  39.         startButton = (Button)findViewById(R.id.get2);
  40.  
  41.         //startButton.setOnClickListener(startListener);
  42.  
  43.         startButton.setEnabled(false);
  44.  
  45.                        .
  46.  
  47.                        .
  48.  
  49.                        .
  50.  
  51.     }  
  52.  
  53. }
  54.  
  55.  
  56.  
  57.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class List5 extends ListActivity {
  2.  
  3.  
  4.  
  5.     @Override
  6.  
  7.     public void onCreate(Bundle icicle) {
  8.  
  9.         super.onCreate(icicle);
  10.  
  11.  
  12.  
  13.         setListAdapter(new MyListAdapter(this));
  14.  
  15.     }
  16.  
  17.  
  18.  
  19.     private class MyListAdapter extends BaseAdapter {
  20.  
  21.         public MyListAdapter(Context context) {
  22.  
  23.             mContext = context;                            }
  24.  
  25.  
  26.  
  27.         public int getCount() {
  28.  
  29.             return mStrings.length;  }
  30.  
  31.  
  32.  
  33.         public boolean areAllItemsSelectable() {
  34.  
  35.             return false;   }
  36.  
  37.  
  38.  
  39.         public boolean isSelectable(int position) {
  40.  
  41.             return !mStrings[position].startsWith("-");   }
  42.  
  43.  
  44.  
  45.         public Object getItem(int position) {
  46.  
  47.             return position;   }
  48.  
  49.  
  50.  
  51.         public long getItemId(int position) {
  52.  
  53.             return position;   }
  54.  
  55.  
  56.  
  57.         public View getView(int position, View convertView, ViewGroup parent) {
  58.  
  59.             TextView tv;
  60.  
  61.             if (convertView == null) {
  62.  
  63.                 tv = new TextView(mContext);
  64.  
  65.             } else {
  66.  
  67.                 tv = (TextView) convertView;
  68.  
  69.             }
  70.  
  71.             tv.setText(mStrings[position]);
  72.  
  73.             return tv;
  74.  
  75.         }
  76.  
  77.  
  78.  
  79.         private Context mContext;
  80.  
  81.     }
  82.  
  83.    
  84.  
  85.     private String[] mStrings = {
  86.  
  87.             "----------",
  88.  
  89.             "----------",
  90.  
  91.             "Abbaye de Belloc",
  92.  
  93.             "Abbaye du Mont des Cats",
  94.  
  95.             "Abertam",
  96.  
  97.             "----------",
  98.  
  99.                   .
  100.  
  101.                   .
  102.  
  103.                   .
  104.  
  105.     };
  106.  
  107.  
  108.  
  109. }
  110.  
  111.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
Jimmy Malibu
Freshman
Freshman
 
Posts: 5
Joined: Fri May 23, 2008 10:30 am

Top

Postby cgreen » Mon Jul 28, 2008 10:12 am

i've tried something similar. this won't happen to work, because the ListActivity is designed to be an activity by itself. afaik there may only be one activity at a time.

workarounds:
you could access buttons via the menue and use the ListActivity as the main Activity.
or
you could use your buttons in the main activity and start you ListActivity as a SubActivity.


maybe you could dismantle some of the ListActivity-Layout and add it to your Konsole to do the work ?
User avatar
cgreen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Wed Jul 16, 2008 10:16 am

Re:

Postby Jimmy Malibu » Mon Jul 28, 2008 12:01 pm

Hallo!
I have the buttons in the ListActivity now and it works with the order setContentView(R.layout.eingabefeld);.
The list is no problem too with the order setListAdapter(mAdapter);.
But both to the same time is not possible only one of them. Is the problem perhabs the xml?
My new code:


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class List5 extends ListActivity {
  3.  
  4.        
  5.  
  6.         MyListAdapter mAdapter;
  7.  
  8.         Button initialiseButton;
  9.  
  10.  
  11.  
  12.         @Override
  13.  
  14.         public void onCreate(Bundle icicle) {
  15.  
  16.                 super.onCreate(icicle);
  17.  
  18.                 setContentView(R.layout.eingabefeld);
  19.  
  20.  
  21.  
  22.                 mAdapter = new MyListAdapter(this);
  23.  
  24.                 setListAdapter(mAdapter);
  25.  
  26.                
  27.  
  28.                 // initialiseButton = (Button)findViewById(R.id.get2);
  29.  
  30.         }
  31.  
  32.  
  33.  
  34.  
  35.  
  36.         public class MyListAdapter extends BaseAdapter {
  37.  
  38.                 public MyListAdapter(Context context) {
  39.  
  40.                         mContext = context;
  41.  
  42.                 }
  43.  
  44.  
  45.  
  46.                 public int getCount() {
  47.  
  48.                         return mStrings.length;
  49.  
  50.                 }
  51.  
  52.  
  53.  
  54.                 public boolean areAllItemsSelectable() {
  55.  
  56.                         return false;
  57.  
  58.                 }
  59.  
  60.  
  61.  
  62.                 public boolean isSelectable(int position) {
  63.  
  64.                         return !mStrings[position].startsWith("-");
  65.  
  66.                 }
  67.  
  68.  
  69.  
  70.                 public Object getItem(int position) {
  71.  
  72.                         return position;
  73.  
  74.                 }
  75.  
  76.  
  77.  
  78.                 public long getItemId(int position) {
  79.  
  80.                         return position;
  81.  
  82.                 }
  83.  
  84.  
  85.  
  86.                 public View getView(int position, View convertView, ViewGroup parent) {
  87.  
  88.                         TextView tv;
  89.  
  90.                         if (convertView == null) {
  91.  
  92.                                 tv = new TextView(mContext);
  93.  
  94.                         } else {
  95.  
  96.                                 tv = (TextView) convertView;
  97.  
  98.                         }
  99.  
  100.                         tv.setText(mStrings[position]);
  101.  
  102.                         return tv;
  103.  
  104.                 }
  105.  
  106.  
  107.  
  108.                 private Context mContext;
  109.  
  110.  
  111.  
  112.         }
  113.  
  114.  
  115.  
  116.         public String[] mStrings = { "----------", "----------",
  117.  
  118.                         "Abbaye de Belloc\n", "Abbaye du Mont des Cats", "Abertam",
  119.  
  120.                         "----------", "Abondance", "----------", "Ackawi", "Acorn",
  121.  
  122.                         "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag",
  123.  
  124.                         "----------", "Airedale", "Aisy Cendre", "----------",
  125.  
  126.                         "Allgauer Emmentaler", "Alverca", "Ambert", "American Cheese",
  127.  
  128.                         "Ami du Chambertin", "----------", "----------", "Anejo Enchilado",
  129.  
  130.                         "Anneau du Vic-Bilh", "Anthoriro", "----------", "----------", };
  131.  
  132. }
  133.  
  134.  
Parsed in 0.042 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.        android:layout_width="wrap_content"
  7.  
  8.        android:layout_height="wrap_content">
  9.  
  10.             android:orientation="vertical"
  11.  
  12.             android:gravity="bottom">
  13.  
  14.            
  15.  
  16.             <LinearLayout
  17.  
  18.        android:layout_width="wrap_content"
  19.  
  20.        android:layout_height="wrap_content">
  21.  
  22.             android:orientation="horizontal"
  23.  
  24.              
  25.  
  26.                        
  27.  
  28.       <Button android:id="@+id/get1"
  29.  
  30.        android:layout_width="wrap_content" android:layout_height="wrap_content"
  31.  
  32.        android:layout_weight="0"
  33.  
  34.        android:text="@string/bottom1">
  35.  
  36.         <requestFocus />
  37.  
  38.       </Button>
  39.  
  40. <FrameLayout
  41.  
  42.    android:layout_width="fill_parent"
  43.  
  44.    android:layout_height="fill_parent">
  45.  
  46.     android:orientation="vertical">
  47.  
  48.    
  49.  
  50.      <ListView android:id="@android:id/list"
  51.  
  52.        android:layout_width="fill_parent"
  53.  
  54.        android:layout_height="0dip"
  55.  
  56.        android:layout_weight="1"  
  57.  
  58.        android:drawSelectorOnTop="false" />
  59.  
  60.          
  61.  
  62.   </FrameLayout>
  63.  
  64. </LinearLayout>
  65.  
  66.  
  67.  
  68.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
Jimmy Malibu
Freshman
Freshman
 
Posts: 5
Joined: Fri May 23, 2008 10:30 am

Re:

Postby Jimmy Malibu » Mon Jul 28, 2008 12:53 pm

Hallo!

The problem is resolved.
My xml layout was not correct.
But thanks for your help :D

Jimmy Malibu
Jimmy Malibu
Freshman
Freshman
 
Posts: 5
Joined: Fri May 23, 2008 10:30 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests