0% found this document useful (0 votes)
8 views3 pages

Shipping

Uploaded by

ManuHiremattBS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Shipping

Uploaded by

ManuHiremattBS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

MainActivity.

java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void OnButtonClick(View v) {


if (v.getId() == R.id.button) {

Intent i = new Intent(this, order.class);


startActivity(i);
}
}}
activitymain.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_centerInParent="true">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:id="@+id/username"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Address"
android:id="@+id/password"

/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter"
android:background="#3f76ff"
android:textColor="#fff"
android:id="@+id/button"
android:onClick="OnButtonClick"/>

</LinearLayout>
</RelativeLayout>

order.java
public class order extends AppCompatActivity {

ListView listView ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order);
// Get ListView object from xml
listView = (ListView) findViewById(R.id.list);

// Defined Array values to show in ListView


String[] values = new String[] { "item1",
"item2",
"item3",
"item4",
"item5",
"item6",
"item7",
"item8"
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);

// Assign adapter to ListView


listView.setAdapter(adapter);

// ListView Item Click Listener


listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

// ListView Clicked item index


int itemPosition = position;

// ListView Clicked item value


String itemValue = (String)
listView.getItemAtPosition(position);

// Show Alert
Toast.makeText(getApplicationContext(),
"Position :"+itemPosition+" ListItem : " +itemValue ,
Toast.LENGTH_LONG)
.show();

});
}

activityorder.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

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

</LinearLayout>

You might also like