0

Im new to android..

I have a List view. For example List view contains "One, Two, Three,Four,Five". When i select the "Two" from list, i should display the "Two" as tittle for next layout content details of "Two"

How to get this? Any one help me. Thanks in advance.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Nexttopic" >
<ListView
    android1:id="@+id/List_view"
    android1:layout_width="match_parent"
    android1:layout_height="250dp"
    android1:layout_centerHorizontal="true"
    android1:layout_centerVertical="true"
     android:background="@drawable/bg">
</ListView>
 </RelativeLayout>
Make it Simple
  • 1,832
  • 5
  • 32
  • 57

4 Answers4

2
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    TextView listitem = (TextView) view.findViewById(R.id.textView1);
    String title = listitem.getText().toString();

    Intent intent = new Intent(getActivity(),NextActivity.class);
    intent.putExtra("SelectedListItem",title);
    startActivity(intent);
    }
});

NextActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.nextlayout);

    String title = getIntent().getStringExtra("SelectedListItem");
    setTitle(title);

}
SKK
  • 5,261
  • 3
  • 27
  • 39
0

This is way to change title

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(R.layout.main);

if ( customTitleSupported ) {
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle);
}

final TextView myTitleText = (TextView) findViewById(R.id.myTitle);
if ( myTitleText != null ) {
    myTitleText.setText("========= NEW TITLE ==========");
    myTitleText.setBackgroundColor(Color.GREEN);
}

}

Prabu
  • 1,441
  • 15
  • 20
0

Try this link:https://stackoverflow.com/a/2417104/670981, otherwise you have to update your question. Is your detail activity "where your selected shows" a Fragment or just an Activity?

Community
  • 1
  • 1
ernestkamara
  • 75
  • 1
  • 9
0

I can't remember exactly but its something like

getActionBar().setTitle("My new title");

I believe if this is a older android version, I.e. one that doesn't support action bar then you can just use setTitle("My Title");

It also gets set based on the android:label you define for the activity in the manifest file.

Boardy
  • 35,417
  • 104
  • 256
  • 447