i have done the following code in android studio.
now i want to view a each element of the listview in a separate view when it is clicked
MAINACTIVITY.JAVA
package com.example.ramneekkashyap.app2;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
Button _loginBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_loginBtn = (Button) findViewById(R.id.btn_login);
_loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ORGANISATIONListActivity.class);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
ACTIVITY_MAIN.XML
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:removed="#ffffffff">
<textview android:text="@string/hello_ORGANISATION" android:layout_width="match_parent">
android:layout_height="wrap_content"
android:removed="#ff7bffff"
android:textColor="#ff000000"
android:textSize="26dp"
android:id="@+id/textView" />
<linearlayout>
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/textView"
android:id="@+id/linearLayout">
<textview>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="User Name"
android:id="@+id/textView2"
android:textColor="#ff000000" />
<edittext>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/id_of_the_username_field"
android:layout_weight="1" />
</edittext></textview></linearlayout>
<linearlayout>
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/linearLayout"
android:id="@+id/linearLayout2">
<textview>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Password: "
android:id="@+id/textView3"
android:textColor="#ff000000" />
<edittext>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/editText2"
android:layout_weight="1" />
</edittext></textview></linearlayout>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="LOGIN"
android:id="@+id/btn_login"
android:layout_below="@+id/linearLayout2"
android:layout_centerHorizontal="true"
android:textSize="25dp" />
</textview></relativelayout>
ORGANISATIONLISTACTIVITY.JAVA
package com.example.ramneekkashyap.app2;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class ORGANISATIONListActivity extends ListActivity {
private ArrayAdapter ORGANISATIONItemArrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ORGANISATION_list);
ORGANISATIONItemArrayAdapter = new ORGANISATIONAdapter(this, new String[10]);
setListAdapter(ORGANISATIONItemArrayAdapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
TextView t = (TextView) v.findViewById(R.id.ORGANISATIONTitle);
t.setText("ORGANISATION Clicked");
}
}
ORGANISATIONADAPTER.JAVA
package com.example.ramneekkashyap.app2;
import android.view.ViewGroup;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
public class ORGANISATIONAdapter extends ArrayAdapter{
private LayoutInflater inflater;
public ORGANISATIONAdapter(Activity activity, String[] items){
super(activity, R.layout.row_ORGANISATION, items);
inflater = activity.getWindow().getLayoutInflater();
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
return inflater.inflate(R.layout.row_ORGANISATION, parent, false);
}
}
ACTIVITY_ORGANISATION_ADAPTER.XML
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.ramneekkashyap.app2.ORGANISATIONAdapter">
<textview android:text="@string/hello_world" android:layout_width="wrap_content">
android:layout_height="wrap_content" />
</textview></relativelayout>
ROW_ORGANISATION.XML
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/user_profile"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp" />
<linearlayout>
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:gravity="left" >
<textview>
android:id="@+id/ORGANISATIONTitle"
android:layout_width="match_parent"
android:layout_height="wrap_removed"
android:text="Header Text"
android:textSize="19sp"
android:textColor="#222222"
android:textStyle="bold" />
<textview>
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ORGANISATION body text here"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:lines="3"
android:textColor="#666666"
android:textSize="14sp" />
<textview>
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="20 Nov 2013"
android:layout_marginTop="5dp"
android:textColor="#999999"
android:textSize="12sp" />
</textview></textview></textview></linearlayout>
</linearlayout>
ACTIVITY_ORGANISATION_LIST.XML
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ramneekkashyap.app2.ORGANISATIONListActivity$PlaceholderFragment" >
<listview>
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</listview>
</relativelayout>