• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to change the header dynamically in android by clicking on any view lyk textview or button ?

 
arjun narahari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need to change my text in the header when i click on the textview , i made my best effort to do somethings, but i m not getting the result
i will post the code and if anyone can help me out and tell me where i m going wrong , it will be of great help

this is my results.xml where my listview and the header with textview(the one which is to be set inside the java code) is there ,


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White" >

<RelativeLayout
android:id="@+id/rltHeader"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#27acc3" >

<ImageView
android:id="@+id/imgBackReuslt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
androidnClick="onClick"
android:src="@drawable/arrow" />

<TextView
android:id="@+id/txtHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="@color/White"
android:textSize="20dp"
android:textStyle="bold" />
</RelativeLayout>

<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/rltHeader"
android:layout_marginRight="5dp"
android:divider="@color/LightGray"
android:dividerHeight="4px" >
</ListView>

</RelativeLayout>

this is my another xml where i have displayed how the listviews every Row will appear

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



<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp">

<RelativeLayout
android:id="@+id/rltRow"
android:layout_width="17dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:background="@drawable/r_list" >
</RelativeLayout>

<ImageView
android:id="@+id/imageView1"
android:layout_width="83dp"
android:layout_height="80dp"
android:layout_alignBottom="@+id/rltRow"
android:layout_alignParentRight="true" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView1"
android:layout_marginLeft="16dp"
android:layout_marginTop="22dp"
android:layout_toRightOf="@+id/rltRow"
android:text="TextView"
android:textColor="@color/Black"
android:textSize="14dp" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView2"
android:layout_alignLeft="@+id/textView2"
android:text="TextView"
android:textColor="@color/Black" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/rltRow"
android:layout_alignLeft="@+id/textView2"
android:text="TextView"
android:textColor="@color/Black" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_alignTop="@+id/imageView1"
android:text="TextView"
android:textColor="@color/Black"
android:textSize="12dp" />

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:text="TextView"
android:textColor="@color/Black"
android:textSize="12dp" />
</RelativeLayout>

</RelativeLayout>

Now the Java part
This is the List_Activity class where i have displayed all the textviews , there are 6 textviews which when clicked , an activity will appear Results.java , for all the textviews when clicked the same activity Results.java is opened

package com.demo.Test;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class Family_List_Activity extends Activity {
ImageView iv;
TextView t1, t2, t3, t4, t5, t6, headervalue;
String header_result = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_info);
iv = (ImageView) findViewById(R.id.imgBackReuslt);
t1 = (TextView) findViewById(R.id.text1);
t2 = (TextView) findViewById(R.id.text2);
t3 = (TextView) findViewById(R.id.text3);
t4 = (TextView) findViewById(R.id.text4);
t5 = (TextView) findViewById(R.id.text5);
t6 = (TextView) findViewById(R.id.text6);

t1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.demo.Test.RESULTS");
intent.putExtra("Results for Self", header_result);
startActivity(intent);
}
});
t2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.demo.Test.RESULTS");
intent.putExtra("Results for Mary(Wife)", header_result);
startActivity(intent);
}
});
t3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// name = t3.getText().toString();
Intent intent = new Intent("com.demo.Test.RESULTS");
intent.putExtra("Results for Alex(Child-1)", header_result);
startActivity(intent);
}
});
t4.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.demo.Test.RESULTS");
intent.putExtra("Results for Steven(Child-2)", header_result);
startActivity(intent);
}
});
t5.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.demo.Test.RESULTS");
intent.putExtra("Results for Robert(Father)", header_result);
startActivity(intent);
}
});
t6.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.demo.Test.RESULTS");
intent.putExtra("Results for Diana(Mother)", header_result);
startActivity(intent);
}
});

}

public void onClick(View v) {
super.onBackPressed();
finish();
}
}

Now the main class Results.java , the activity which opens when clicked on the textviews described the previous class

package com.demo.Test;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class Results extends Activity {
TextView header;
ImageView iv;
ListView lv;
String title;

int[] images = { R.drawable.photo_bg, R.drawable.photo_bg,
R.drawable.photo_bg, R.drawable.photo_bg, R.drawable.photo_bg,
R.drawable.b_list, R.drawable.g_list, R.drawable.r_list,
R.drawable.v_list };

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.results);
iv = (ImageView) findViewById(R.id.imgBackReuslt);
header = (TextView) findViewById(R.id.txtHeader);

lv = (ListView) findViewById(R.id.listView1);
Bundle extras = getIntent().getExtras();
if (extras != null) {
title = extras.getString("header_result");
}
ResultsAdapter adapter = new ResultsAdapter(getBaseContext(), doc,
diag, dt, images, docname, diagname);
lv.setAdapter(adapter);
}

so what changes i have to make so that the header text gets changed when i click on the textviews in the List_Activity accordingly
any suggestions are welcomed

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic