View and Viewgroups..

Put your problem here if it does not fit any of the other categories.

View and Viewgroups..

Postby sommeralex » Wed Jan 30, 2008 2:19 am

Hello!

How can i make a View which is a ViewGroup consisting of an ImageView and (transparent) TextView in with a linear Layout?

-> i just want to have icons with a text under them to create my own menu..

thx..

i am trying to adapt the grid1 example, maybe some could help me:

imageView.setImageBitmap(icon); is wrong - its just to show the idea. what i want to have at the end is the same menu as android is using..

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4.    public class TextIconView extends ViewGroup {
  5.  
  6.  
  7.  
  8.         private Image icon;
  9.  
  10.         private String text;
  11.  
  12.        
  13.  
  14.         private ImageView imageView;
  15.  
  16.         private TextView textView;
  17.  
  18.        
  19.  
  20.         private Context context;
  21.  
  22.                
  23.  
  24.        
  25.  
  26.                 public TextIconView(Context context, AttributeSet attrs,
  27.  
  28.                                 Map inflateParams, int defStyle, Image icon, String text) {
  29.  
  30.                        
  31.  
  32.                                                
  33.  
  34.                         super(context, attrs, inflateParams, defStyle);
  35.  
  36.                         this.icon = icon;
  37.  
  38.                         this.text = text;
  39.  
  40.                         this.context = context;
  41.  
  42.                         setImageView();
  43.  
  44.                         setTextView();
  45.  
  46.                 }
  47.  
  48.  
  49.  
  50.                 public TextIconView(Context context, AttributeSet attrs,
  51.  
  52.                                 Map inflateParams, Image icon, String text) {
  53.  
  54.                        
  55.  
  56.  
  57.  
  58.                         super(context, attrs, inflateParams);
  59.  
  60.                         this.icon = icon;
  61.  
  62.                         this.text = text;
  63.  
  64.                         this.context = context;
  65.  
  66.                         setImageView();
  67.  
  68.                         setTextView();
  69.  
  70.                 }
  71.  
  72.                
  73.  
  74.                 public TextIconView(Context context, Image icon, String text) {
  75.  
  76.                        
  77.  
  78.                        
  79.  
  80.                         super(context);
  81.  
  82.                         this.icon = icon;
  83.  
  84.                         this.text = text;
  85.  
  86.                         this.context = context;
  87.  
  88.                         setImageView();
  89.  
  90.                         setTextView();
  91.  
  92.                        
  93.  
  94.                        
  95.  
  96.                 }
  97.  
  98.                
  99.  
  100.                 protected void onLayout(boolean arg0, int arg1, int arg2, int arg3,
  101.  
  102.                                 int arg4, int arg5, int arg6) {
  103.  
  104.                         // TODO Auto-generated method stub
  105.  
  106.                        
  107.  
  108.                 }
  109.  
  110.        
  111.  
  112.                 private void setTextView(){
  113.  
  114.                        
  115.  
  116.                         textView = new TextView(context);
  117.  
  118.                         textView.setText(text);
  119.  
  120.                         this.addView(textView);
  121.  
  122.                        
  123.  
  124.                 }
  125.  
  126.                
  127.  
  128.                 private void setImageView(){
  129.  
  130.                        
  131.  
  132.                         imageView = new ImageView(context);
  133.  
  134.                         imageView.setImageBitmap(icon);
  135.  
  136.                         this.addView(imageView);
  137.  
  138.                        
  139.  
  140.                 }
  141.  
  142.                
  143.  
  144.        
  145.  
  146.     }
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Top

Postby plusminus » Wed Jan 30, 2008 11:13 am

Hello sommeralex,

so something similar to this... is what you want to do, right :?:
Image


You could have a look at :src: the code of my Weather-Forecast-Tutorial for the specific snippets (in there, search for 'SingleWeatherInfoView').

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby sommeralex » Wed Jan 30, 2008 4:51 pm

thank you very much!! and how can i put a border on it when it is selected?
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby sommeralex » Wed Jan 30, 2008 5:06 pm

i tried to make this:

1.

public class SingleWeatherInfoView extends LinearLayout implements android.view.View.OnClickListener {

public void onClick(View arg0) {
// TODO Auto-generated method stub
setTempString("hello");
}

}

but when i click on it, its not set to "hello"..
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 20 guests