Tampilkan postingan dengan label listview. Tampilkan semua postingan
Tampilkan postingan dengan label listview. Tampilkan semua postingan

Delete A row in ListView with Animation

Posted by Unknown Senin, 17 Juni 2013 0 komentar
Listview is simply a group of view that displays a list of scrolling items. "Adapters" are used to insert list items to the list.By default we are able to provide only text as list items.In order to delete a row from listview, copy or download this javacode and try yourself.
Also see here :
java file :
public class SimpleListViewActivity extends Activity {

private ListView mainListView;
private ArrayAdapter<String> listAdapter;
ArrayList<String> all_rowtext = new ArrayList<String>() ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Find the ListView resource.
mainListView = (ListView) findViewById(R.id.mainListView);
all_rowtext.add("Angel");
all_rowtext.add("Mark");
all_rowtext.add("Coding");
all_rowtext.add("Playground");
all_rowtext.add("For");
all_rowtext.add("All");
all_rowtext.add("Android");
all_rowtext.add("Coderz");
// Create ArrayAdapter using the planet list.
listAdapter = new ArrayAdapter<String>(this, R.layout.singlerow,
all_rowtext);
// Set the ArrayAdapter as the ListView's adapter.
mainListView.setAdapter(listAdapter);
mainListView
.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,
View rowView, int positon, long id) {
Toast.makeText(rowView.getContext(), "" + positon,
Toast.LENGTH_LONG).show();
removeListItem(rowView, positon);
}
});
}

protected void removeListItem(View rowView, final int positon) {
final Animation animation = AnimationUtils.loadAnimation(
SimpleListViewActivity.this, android.R.anim.slide_in_left);
rowView.startAnimation(animation);
Handler handle = new Handler();
handle.postDelayed(new Runnable() {

public void run() {
all_rowtext.remove(positon);
listAdapter.notifyDataSetChanged();
}
}, 1000);
}}

Baca Selengkapnya ....

Parsing an XML from Online in Android

Posted by Unknown Senin, 04 Maret 2013 0 komentar
Create a fresh project and name it ParseXMLDemo
Then in the ParseXMLDemo.java file copy this code
|
import java.util.ArrayList;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class ParseXMLDemo extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

ArrayList<String> mylist = new ArrayList<String>();
String xml = ParseXMLMethods.getXML();
Document doc = ParseXMLMethods.XMLfromString(xml);
int numResults = ParseXMLMethods.numResults(doc);

if((numResults <= 0)){
Toast.makeText(ParseXMLDemo.this, "There is no data in the xml file", Toast.LENGTH_LONG).show();
finish();
}

NodeList children = doc.getElementsByTagName("os");
for (int i = 0; i < children.getLength(); i++)
{
HashMap<string string=""> map =new HashMap<string string="">();
Element e = (Element)children.item(i);
map.put("id", ParseXMLMethods.getValue(e, "id"));
map.put("name", ParseXMLMethods.getValue(e, "name"));
map.put("site", ParseXMLMethods.getValue(e, "site"));
mylist.add(map);
}
ListAdapter adapter = new SimpleAdapter(this,mylist ,R .layout.list_layout,
new String[] { "name", "site" },
new int[] { R.id.title, R.id.subtitle});

setListAdapter(adapter);


final ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View view, int position, long id) {
@SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
Toast.makeText(ParseXMLDemo.this,o.get("name"), Toast.LENGTH_LONG).show();
}
});
} }

Now create another java file inside the src folder and name it ParseXMLMethods.java and copy this contents into it.
import java.io.IOException;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class ParseXMLMethods {

public final static Document XMLfromString(String xml){

Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
}
catch (ParserConfigurationException e) {
System.out.println("XML parse error: " + e.getMessage());
return null;
}
catch (SAXException e) {
System.out.println("Wrong XML file structure: " +e.getMessage());
return null;
}
catch (IOException e) {
System.out.println("I/O exeption: " +e.getMessage());
return null;
}
return doc;
}
public final static String getElementValue( Node elem ) {
Node kid;
if( elem != null){
if (elem.hasChildNodes()){
for( kid = elem.getFirstChild(); kid != null;kid = kid.getNextSibling() ){
if( kid.getNodeType() == Node.TEXT_NODE ){
return kid.getNodeValue();
}
}
}
}
return "";
}
public static String getXML(){
String line = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://new ABC.com/xml/test.xml");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
line = EntityUtils.toString(httpEntity);
} catch (Exception e) {
line = "Internet Connection Error >> " + e.getMessage();
}
return line;
}

public static int numResults(Document doc)
{
Node results = doc.getDocumentElement();
int res = -1;
try
{
res = Integer.valueOf(results.getAttributes()
.getNamedItem("count").getNodeValue());
}catch(Exception e ){
res = -1;
}
return res;
}

public static String getValue(Element item, String str)
{
NodeList n = item.getElementsByTagName(str);
return ParseXMLMethods.getElementValue(n.item(0));
}
}
in main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FF0000"
android:drawSelectorOnTop="false"/>
</LinearLayout>
list_layout.xml:
< ?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="7dp">
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:padding="2dp"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="@+id/subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textSize="14dp"
android:textColor="#000000"/>
</LinearLayout>
Strings.xml:
<?xml version="1.0" encoding="utf-8"?> 
<resources>
<string name="hello"> Hello World, ParseXMLDemo!</string>
<string name="app_name"> ParseXMLDemo New ABC.com</string>
</resources>

Baca Selengkapnya ....

ListView in Alphabetic Order in ANDROID

Posted by Unknown Jumat, 01 Maret 2013 0 komentar
Java class: 
public class MainActivity extends ListActivity {
static final String[] items = new String[] { "Babbage","Boole", "Berners-Lee",
"Atanasoff", "Allen","Cormack", "Cray","Dijkstra","Dix","Dewey",
"Erdos","Zebra" };

ArrayAdapter<string> arrayadapter;
ListView listview;
ArrayList<string> arraylist;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
arraylist= new ArrayList<String>();
for(int i=0;i<items.length;i++)
{
arraylist.add(FRUITS[i]);
}
Collections.sort(arraylist );//for sorting arraylist
arrayadapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arraylist);
listview=getListView();
listview.setAdapter(arrayadapter);
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent,View view,
int position, long id)
{
Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_SHORT).show();
}});}}
                 

Baca Selengkapnya ....

Single Selection ListView in android

Posted by Unknown 0 komentar
main.xml
< ?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:id="@android:id/list"
android:cacheColorHint="#00000000"
android:scrollbars="none"
android:fadingEdge="vertical"
android:soundEffectsEnabled="true"
android:dividerHeight="1px"
android:padding="5dip"
android:smoothScrollbar="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginBottom="10dip"
android:layout_weight="1"/>

</LinearLayout>
java class
public class ListView1 extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

String[] phonenames = new String[] { "Android", "Windows7","Symbian", "iPhone",
"Android", "Windows7", "Symbian", "iPhone",
"Android", "Windows7", "Symbian", "iPhone" };
setListAdapter(new ArrayAdapter<string>(this,
android.R.layout.simple_list_item_single_choice,android.R.id.text1, phonenames));
ListView list = getListView();
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

}
}
                           

Baca Selengkapnya ....

Expandable ListView in ANDROID

Posted by Unknown 0 komentar
java.class

public class Expandablelistview extends ExpandableListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.expandablelistview);
SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
this,
createGroupList(),
R.layout.group_row,
new String[] { "Item" },
new int[] { R.id.row_name },
createChildList(),
R.layout.child_row,
new String[] {"Sub Item"},
new int[] { R.id.grp_child});
setListAdapter( expListAdapter );
}

// hash map for row

private List createGroupList() {
ArrayList result = new ArrayList();
for (int i = 0; i < 15; ++i) { // 15 groups........
HashMap m = new HashMap();
m.put("Item", "Item " + i); // the key and it's value.
result.add(m);
}
return (List) result;
}

/* creatin the HashMap for the children */

private List createChildList() {
ArrayList result = new ArrayList();
for (int i = 0; i < 15; ++i) {
ArrayList secList = new ArrayList();
for (int n = 0; n < 3; n++)
{
HashMap child = new HashMap();
child.put("Sub Item", "Sub Item " + n);
secList.add(child);
}
result.add(secList);
}
return result;
}


public void onGroupExpand(int groupPosition) {
try
{
System.out.println("Group exapanding
Listener => groupPosition = "
+ groupPosition);
} catch (Exception e) {
System.out.println(" groupPosition Errrr +++ "
+ e.getMessage());
} } }

expandablelistview.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ExpandableListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bkg"/>

<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No items"/>
</LinearLayout>

child_row.xml:
 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
< TextView android:id="@+id/grp_child"
android:paddingLeft="50px"
android:focusable="false"
android:textSize="14px"
android:textStyle="normal"
android:layout_width="150px"
android:layout_height="wrap_content"/>
</LinearLayout>
group_row.xml

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

<TextView android:id="@+id/row_name"
android:paddingLeft="50px"
android:textSize="20px"
android:textStyle="normal"
android:layout_width="320px"
android:layout_height="wrap_content"/>

</LinearLayout>


Baca Selengkapnya ....

Android – Bullets in ListView

Posted by Unknown Senin, 18 Februari 2013 0 komentar
main.xml :
<?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"
android:padding="10dp">

<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="@android:color/transparent"
android:divider="@null"/>
</LinearLayout>
create a bullet.xml in drawable folder:
<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:height="6dp"
android:width="6dp"/>
<solid android:color="#FF00F0"/>
</shape>
list_item.xml for creating custom listview:
<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/itemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/bullet"
android:drawablePadding="8dp"
android:padding="5dp"
android:text="List Item"
android:textSize="20sp"/>
BulletListViewActivity.java
public class BulletedListViewActivity extends Activity {
/** Called when the activity is first created. */
ArrayList<string> listCountry;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
prepareList();
ListView listView = (ListView)findViewById(R.id.listView);
listView.setAdapter(new ArrayAdapter<string>(
this, R.layout.list_item, listCountry));
}
public void prepareList()
{
listCountry = new ArrayList<string>();
listCountry.add("India");
listCountry.add("Brazil");
listCountry.add("Canada");
listCountry.add("China");
listCountry.add("France");
listCountry.add("Germany");
listCountry.add("Iran");
listCountry.add("Italy");
listCountry.add("Japan");
listCountry.add("Korea");
listCountry.add("Mexico");
listCountry.add("Netherlands");
listCountry.add("Portugal");
listCountry.add("Russia");
listCountry.add("Saudi Arabia");
listCountry.add("Spain");
listCountry.add("Turkey");
listCountry.add("United Kingdom");
listCountry.add("United States");
}}

                

Baca Selengkapnya ....

Using DialogFragments in Android

Posted by Unknown Minggu, 17 Februari 2013 0 komentar
MainActivity.java :
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fm = getSupportFragmentManager();
dialogfragment testDialog = new dialogfragment();
testDialog.setRetainInstance(true);
testDialog.show(fm, "fragment_name");
}}
Dialogfragment.java :
public class Dialogfragment extends DialogFragment {    
public void TestDialog() {
// Empty constructor required for DialogFragment
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog, container);
return view;
} }
dialog.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/edit_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/lbl_your_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello from Mark's Playground, DialogFragment Demo"/>
</LinearLayout>

  


Baca Selengkapnya ....

Fragmentation In Android

Posted by Unknown 0 komentar

See more basics on Android along with interview questions

Fragments are a portion of an Activity:
Load a fragment Activity to call a fragment :
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} }
activity_main :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<fragment
android:id="@+id/titles"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
class="com.example.googlefragment.TitlesFragment"/>
//calls the fragment
</LinearLayout>
TitlesFragment :
public class TitlesFragment extends android.support.v4.app.ListFragment {
boolean mDualPane;
int mCurCheckPosition = 0;
String titles[] = { "Item one", "Item two", "Item three" };
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Populate list with our static array of titles.setListAdapter(new ArrayAdapter(getActivity(),
android.R.layout.simple_dropdown_item_1line,titles));

// Check to see if we have a frame in which to embed the details
// fragment directly in the containing UI.
View detailsFrame = getActivity().findViewById(R.id.details);
mDualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE;
if (savedInstanceState != null) {
// Restore last state for checked position.
mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
}
if (mDualPane) {
// In dual-pane mode, the list view highlights the selected item.
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
// Make sure our UI is in the correct state.
showDetails(mCurCheckPosition);
}else
{
System.out.println("NOT DUAL");
} }

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("curChoice", mCurCheckPosition);
}
@Override
public void onListItemClick(ListView l, View v,int position,long id) {
showDetails(position);
}
void showDetails(int index) {
mCurCheckPosition = index;
if (mDualPane) {
// We can display everything in-place with fragments,so update
// the list to highlight the selected item and show the data.
getListView().setItemChecked(index, true);
// Check what fragment is currently shown,replace if needed.
DetailsFragment details = (DetailsFragment)
getFragmentManager().findFragmentById(R.id.details);
if (details == null || details.getShownIndex()!=index) {
// Make new fragment to show this selection.
details = DetailsFragment.newInstance(index);
// Execute a transaction, replacing any existing fragment
// with this one inside the frame.
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.details, details);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();
}
} else {
// Otherwise we need to launch a new activity to display
// the dialog fragment with selected text.
Intent intent = new Intent();
intent.setClass(getActivity(),DetailsActivity.class);
intent.putExtra("index", index);
startActivity(intent);
} }}
DetailsActivity :
public class DetailsActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
setContentView(R.layout.details_lay);
System.out.println("LANNNNNNNNNNN");
return;
}
if (savedInstanceState == null) {
System.out.println("LLLLLLLLLLL");
Fragment details = new DetailsFragment();
details.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, details).commit();

} } }
details_lay:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/details"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
class="com.example.googlefragment.DetailsFragment"/>
</LinearLayout>
DetailsFragment :
public class DetailsFragment extends Fragment {
static int i = 0;
public static DetailsFragment newInstance(int index) {
DetailsFragment f = new DetailsFragment();
// Supply index input as an argument.
Bundle args = new Bundle();
args.putInt("index", index);
i = index;
f.setArguments(args);
return f;
}
public int getShownIndex() {
return getArguments().getInt("index", 0);
}
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
if (container == null) {
return null;
}
WebView wv = new WebView(getActivity());
wv.loadData("Hello " + i, "text/html", "utf-8");
return wv;
} }
NOTE: Put layout under two separate folder for layout and portrait.


Baca Selengkapnya ....

Creating A Customized ListView in Android

Posted by Unknown Jumat, 04 Januari 2013 0 komentar
Listview is simply a group of view that displays a list of scrolling items. "Adapters" are used to insert list items to the list.By default we are able to provide only text as list items.In order to insert other attributes make a customized listview. Copy or download this javacode and try yourself.
Also see here :
java file :
public class CustomListView extends Activity {
static final String[] items = new String[]{"Sunday","Monday","Tuesday","Wednesday",
"Thursday","Friday",""Saturday"};
ListView listview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listview=(ListView) findViewById(R.id.list);
listview.setAdapter(newCustomListViewAdapter
(this,items));
listview .setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView
arg0, View arg1,int position,long arg3)
{
String value = listview.getItemAtPosition(position).toString();
System.out.println("=============>>>"+value);
}});
} }
xml file: (main)
< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/redbg">
< ListView
android:layout_marginTop="100dp"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
< /RelativeLayout>
CustomAdapter Class:
public class CustomListViewAdapter extends ArrayAdapter {
private final Context context;
private final String[] values;

public CustomListViewAdapter(Context context, String[] values)
{
super(context, R.layout.list_view, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)

{
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.list_view, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.title);
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
textView.setText(values[position]);
// Change icon based on name
String s = values[position];
System.out.println(s);
return rowView;
}}
xml for customizing each row:(list_view)
   < ?xml version="1.0" encoding="utf-8"?> 
< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

< ImageView
android:id="@+id/icon"
android:src="@drawable/heartz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp" />

< TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/icon"
android:paddingBottom="10dp"
android:textColor="#FFFFFF"
android:textSize="16dp" />

< /RelativeLayout>


Baca Selengkapnya ....

Simple ListView in Android

Posted by Unknown 0 komentar
xml page:eazy_list
< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
< ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

< /ListView>
< /RelativeLayout>
java page:
 public class MainActivity extends ListActivity 

{
String[] planets = new String[] { "Mercury", "Venus", "Earth", "Mars",
"Jupiter", "Saturn", "Uranus", "Neptune","Ceres","Pluto"};
ListView lstv;
private ArrayAdapter listAdapter ;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lstv=getListView();
listAdapter = new ArrayAdapter(this,android.R.layout.simple_expandable_list_item_1, planets);
setListAdapter(listAdapter);
}}

Baca Selengkapnya ....
Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of android populer.