Android CheckBox

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Android CheckBox

Postby gomathisankar » Tue Jul 13, 2010 6:42 am

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="8dip"
android:paddingRight="8dip">

<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:drawSelectorOnTop="false" android:scrollbars="none">
</ListView>

<TextView android:id="@+id/phone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>

<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Get"></Button>



</LinearLayout>
----------------------------------------------------------------------------------------------------------------------------------------
Second Layout 2)


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical">
<ScrollView android:id="@+id/ScrollView01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:scrollbars="none"><LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:orientation="vertical" android:layout_height="wrap_content"><TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Contact List" android:textColor="#ffffff" android:textSize="20px" android:textStyle="bold" android:typeface="serif" android:layout_marginTop="12px"></TextView><Spinner android:id="@+id/Spinner01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginTop="4pt"></Spinner></LinearLayout>
</ScrollView><LinearLayout android:id="@+id/LinearLayout03" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal" android:layout_marginTop="12px" android:gravity="center_horizontal"><CheckBox android:id="@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>

<TextView android:id="@+id/TextView02" android:layout_height="wrap_content" android:text="Log Incoming Call" android:layout_width="fill_parent"></TextView>
</LinearLayout>



<LinearLayout android:id="@+id/LinearLayout03" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal" android:gravity="center_horizontal"><CheckBox android:id="@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox><TextView android:id="@+id/TextView02" android:layout_height="wrap_content" android:text="Log Outgoing Call" android:layout_width="fill_parent"></TextView>

</LinearLayout><LinearLayout android:id="@+id/LinearLayout03" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal" android:gravity="center_horizontal"><CheckBox android:id="@+id/CheckBox01" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox><TextView android:id="@+id/TextView02" android:layout_height="wrap_content" android:text="Message" android:layout_width="fill_parent"></TextView>

</LinearLayout><LinearLayout android:id="@+id/LinearLayout04" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal" android:gravity="center_horizontal" android:layout_marginTop="12pt"><Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Cancel" android:ems="8"></Button>
<Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Set" android:ems="8"></Button>
</LinearLayout>
</LinearLayout>


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



1) First programme


package com.contactlistviewactivity;




import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.provider.Contacts.People;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;

/**
* A list view example where the data comes from a cursor.
*/
public class List7 extends ListActivity implements OnClickListener {
ProgressBar p;

public static final String PRIVATE_NUMBER = null;
public static final String UNKNOWN_NUMBER = null;
Button get;
TextView mPhone ;

private static String[] PROJECTION = new String[] {
People._ID, People.NAME, People.NUMBER
};

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_7);
mPhone = (TextView) findViewById(R.id.phone);
get=(Button) this.findViewById(R.id.Button01);
//p=(ProgressBar) this.findViewById(R.id.ProgressBar01);
get.setOnClickListener(this);


//getListView().setOnItemSelectedListener(this);

// Get a cursor with all people
Cursor c = getContentResolver().query(People.CONTENT_URI, PROJECTION, null, null, null);
startManagingCursor(c);
//mPhoneColumnIndex = c.getColumnIndex(People.NUMBER);

ListAdapter adapter= new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_multiple_choice,
// that displays a
// text view
c, new String[] {People.NAME}, new int[] {android.R.id.text1}); // The "text1" view defined in

// the XML template

getListView().setTextFilterEnabled(true);

final ListView list=getListView();
list.setItemsCanFocus(false);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
setListAdapter(adapter);
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

{

Intent intent = new Intent(List7.this,contact.class);
intent.putExtra("selected",PROJECTION );

startActivity(intent);

}
}



/* public void onItemSelected(AdapterView parent, View v, int position, long id) {
if (position >= 0) {
Cursor c = (Cursor) parent.getItemAtPosition(position);
mPhone.setText(c.getString(mPhoneColumnIndex));
}
}

public void onNothingSelected(AdapterView parent) {
mPhone.setText(R.string.list_7_nothing);

}*/

}


2 ) Second Programme


package com.contactlistviewactivity;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.Spinner;

public class contact extends Activity

{
Spinner s;

protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.contact);
s=(Spinner) this.findViewById(R.id.Spinner01);


String[] PROJECTION;
PROJECTION = getIntent().getStringArrayExtra("selected");


}
}



How to make CheckBox particular name select ..Then i need i have get button Click..how to put in particular select name list next layout add spinner ??
gomathisankar
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sat Feb 13, 2010 8:48 am

Top

Return to General

Who is online

Users browsing this forum: No registered users and 4 guests