Showing posts with label widget. Show all posts
Showing posts with label widget. Show all posts

Tuesday, March 20, 2012

ListView with IMAGE


How Can we add Image in List View 




package im.li;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ImagelistviewActivity extends ListActivity {
    /** Called when the activity is first created. */
    String name[]={"Rahul","aju","Vivek","Binnesh","Rehu"};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        ArrayAdapter<String> a=new ArrayAdapter<String>(this, R.layout.main, R.id.offerdetails,name);
        setListAdapter(a);
    }
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);
        Intent i=new Intent(this,second.class);
        startActivity(i);
        }
}

--------------------------------------------------------------------------------------


<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
android:layout_centerInParent="true"
android:id="@+android:id/offerdetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView android:id="@+id/icon" android:layout_width="65dp" android:layout_height="65dp" android:src="@drawable/icon" android:layout_x="238dp" android:layout_y="10dp"></ImageView>
</AbsoluteLayout>





Toast-Widget

Toast

  1. A toast is a view congaing a quick little message for the user
  2. Toast.show()--Show the view for the specified duration.
  3. Toast.makeText (Context context, CharSequence text, int duration);
 import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ToastActivity extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
    EditText et;
    Button bt;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        et=(EditText) findViewById(R.id.editText1);
        bt=(Button) findViewById(R.id.button1);
        bt.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Toast.makeText(this,et.getText().toString(), Toast.LENGTH_SHORT).show();
       
    }
}
----------------------------------------------------------------------------



<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <EditText android:id="@+id/editText1"
    android:layout_height="wrap_content"
    android:layout_x="98dp"
    android:layout_y="101dp"
    android:layout_width="83dp">
    </EditText>
   
    <Button android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:id="@+id/button1"
     android:text="OK"
     android:layout_x="113dp"
     android:layout_y="180dp">
     </Button>
    
</AbsoluteLayout>

Spinner Widget

Spinner-Widget 



 dasdd
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class HelloSpinnerActivity extends Activity implements OnItemSelectedListener{
    /** Called when the activity is first created. */
    Spinner sp;
    ArrayAdapter<String> ad;
    String str[]={"Ajumal","Rahul","Binnesh"};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        sp=(Spinner)findViewById(R.id.spinner);
        ad=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,str);
        ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp.setAdapter(ad);
        sp.setOnItemSelectedListener(this);

        }
    @Override
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub
        Toast.makeText(this,str[arg2], Toast.LENGTH_LONG).show();
       }
    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub       
    }
}

--------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:padding="10dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
       
    />
    <Spinner
        android:id="@+id/spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       
    />

</LinearLayout>

Widget

ListView

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class HelloListViewActivity extends ListActivity {
    /** Called when the activity is first created. */
    TextView t1;
    ArrayAdapter<String> ad;
    String str[]={"jisho","rahul", "Ajumal"};
    @Override
    public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          ad=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,str);
          setListAdapter(ad);
         
           }
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
               Toast.makeText(this, str[position], Toast.LENGTH_LONG).show();
        super.onListItemClick(l, v, position, id);
       
    }
   
}
_____________________________________________________________________________

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <ListView
        android:id="@+android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </ListView>

</LinearLayout>