app showing some irrelevant Text instead of a Textview - android

I am developing an android app, it was working fine till i add textview into main activity layout.
All images are being shown. But instead of textview an irrelevant is being shown on display screen.
Below is the code from mainactivity.java.
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
public class MainActivity extends AppCompatActivity {
ImageButton showBalDialog, showExpDialog, showIncomebtn, showExpbtn;
TextView bal_dialog, total_incomes;
public static final String DB_name = "mydb";
DatabaseHelper m_db;
private String amnt, src, exp, rzn;
private String incomes = "sum";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
m_db = new DatabaseHelper(this);
showBalDialog = findViewById(R.id.btnshowBalDialog);
showExpDialog = findViewById(R.id.btnshowExpDialog);
showIncomebtn = findViewById(R.id.btnshowIncomes);
showExpbtn = findViewById(R.id.btnshowExpenses);
total_incomes = findViewById(R.id.totalincomes);
incomes = String.valueOf(total_incomes);
total_incomes.setText(incomes);
}
}
Below is the code from activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:screenOrientation="portrait"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageButton
android:id="#+id/btnshowBalDialog"
android:scaleType="fitXY"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="20dp"
android:layout_marginTop="40dp"
android:cropToPadding="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#drawable/add_inc"> // this is the image(eye)
</ImageButton>
<ImageButton
android:id="#+id/btnshowExpDialog"
android:scaleType="fitXY"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginEnd="20dp"
android:layout_marginTop="40dp"
android:cropToPadding="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="#drawable/add_exp"> // this is the image(eye)
</ImageButton>
<ImageButton
android:id="#+id/btnshowIncomes"
android:scaleType="fitXY"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="20dp"
android:layout_marginTop="40dp"
android:cropToPadding="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/btnshowBalDialog"
android:background="#drawable/income_his"> // this is the image(eye)
</ImageButton>
<ImageButton
android:id="#+id/btnshowExpenses"
android:scaleType="fitXY"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginEnd="20dp"
android:layout_marginTop="40dp"
android:cropToPadding="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/btnshowExpDialog"
android:background="#drawable/expense_his"> // this is the image(eye)
</ImageButton>
<TextView
android:id="#+id/totalincomes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="20dp"
android:text="TextView"
app:layout_constraintTop_toBottomOf="#id/btnshowIncomes"
app:layout_constraintStart_toStartOf="parent">
</TextView>
</android.support.constraint.ConstraintLayout>
And below what is i am getting instead of Textview on app gui.

You have to do this:
total_incomes.setText(incomes);
your incomes value is already in String no need to use String.valueOf()
instead of
incomes = String.valueOf(total_incomes);
total_incomes.setText(incomes);

total_incomes is the Textview, you are binding the TextView with R.id.totalincome which is present in xml.
incomes = String.valueOf(total_incomes);
total_incomes.setText(incomes);
You are fetching the string value of total_incomes and store it in incomes and the same value you set on total_incomes. so in short you are setting textview id.

Related

TextView onClickListener crashes app when clicked on [duplicate]

This question already has answers here:
Unfortunately MyApp has stopped. How can I solve this?
(23 answers)
findViewById returns null
(4 answers)
Null pointer Exception - findViewById()
(12 answers)
Closed 3 years ago.
I am new in android development. I'm trying to make a simple login and registration form. I have a TextView 'Sign up' which basically takes the user to the registerActivity when clicked on, but when everytime when i click on the sign up textView it crashes my app. I have searched for the solutions but i can't seem to figure out whats causing the crash.
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context=".LoginActivity"
android:orientation="vertical"
android:gravity="center_horizontal"
android:background="#drawable/bg"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_marginTop="70dp"
app:srcCompat="#drawable/logo"
/>
<EditText
android:id="#+id/edittext_username"
android:layout_width="249dp"
android:layout_height="71dp"
android:layout_marginTop="20dp"
android:drawableLeft="#drawable/user"
android:drawablePadding="10dp"
android:textColorHint="#f8f8f8"
android:paddingLeft="15dp"
android:hint="#string/mobile"
android:textColor="#f8f8f8"
android:background="#drawable/rounded_edittext" />
<EditText
android:id="#+id/edittext_password"
android:layout_width="249dp"
android:layout_height="71dp"
android:layout_marginTop="20dp"
android:drawableLeft="#drawable/password"
android:drawablePadding="10dp"
android:textColorHint="#f8f8f8"
android:paddingLeft="15dp"
android:hint="#string/password"
android:textColor="#f8f8f8"
android:background="#drawable/rounded_edittext"/>
<Button
android:id="#+id/button_login"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="#drawable/rounded_buttons"
android:text="#string/login"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Not Registered?"
android:textColor="#000000" />
<TextView
android:id="#+id/textview_register"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:paddingLeft="5dp"
android:textStyle="bold"
android:textColor="#e8170c"
android:text="#string/register"/>
</LinearLayout>
JAVA:
package com.example.careerhunts.raw;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class LoginActivity extends AppCompatActivity {
EditText mTextUsername;
EditText mTextPassword;
Button mButtonLogin;
TextView mTextViewRegister;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
getSupportActionBar().hide(); // hide the title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full
screen
setContentView(R.layout.activity_login);
mTextUsername = findViewById(R.id.edittext_username);
mTextPassword = findViewById(R.id.edittext_password);
mButtonLogin = findViewById(R.id.button_login);
mTextViewRegister = findViewById(R.id.textview_register);
mTextViewRegister.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent registerIntent = new Intent(LoginActivity.this,
RegisterActivity.class);
startActivity(registerIntent);
}
});
}
}
I tested same code, Its's working fine, by guessing i can tell that you may misspelled name of activity_login (may be you assigned different layout which doesnot have text view named textview_register) or may be you dont have activity named RegisterActivity.class.

Android Relative layout spacing between elements

I have this Design in Relative Layout. I have to do some more things.
How can I remove that straight line between two elements ?
How can I increase space between two elements ?
How to display product side by side ?
I have tried several solutions from stackoverflow. Like I have used margin bottom but got no luck.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:background="#drawable/round_corner"
android:layout_marginRight="20dp"
>
<RelativeLayout
android:layout_width="200dp"
android:layout_height="250dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:paddingRight="20dp"
android:paddingLeft="20dp"
>
<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/product_image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:foregroundGravity="center"
app:civ_border_color="#d1b1b1"
/>
<View
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="1dp"
android:layout_marginTop="0dp"
android:background="#drawable/gradient" />
<TextView
android:id="#+id/product_name_english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/product_image"
android:layout_alignTop="#id/product_image"
android:layout_alignRight="#id/product_image"
android:layout_alignBottom="#id/product_image"
android:layout_margin="1dp"
android:gravity="center"
android:text="Hello"
android:textColor="#FFFF"
android:fontFamily="#font/aerial"/>
<TextView
android:id="#+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/product_name_english"
android:layout_centerHorizontal="true"
android:layout_marginTop="-51dp"
android:layout_marginBottom="1dp"
android:fontFamily="#font/aerial"
android:text="Hello"
android:textColor="#FFFF" />
<Button
android:layout_width="250dp"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:layout_marginTop="194dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
android:text="Add to cart"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<Button
android:layout_width="250dp"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:layout_marginTop="224dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
android:text="View Product"
android:textColor="#FFFFFF"
android:textSize="10sp" />
</RelativeLayout>
</FrameLayout>
Here is the listview I am sending to my Adapter
listView = (ListView) findViewById(R.id.product_list);
mAdapter = new all_product_list_ArrayAdapter(all_product.this,data);
listView.setAdapter(mAdapter);
Here is my ArrayAdapter Class :
package com.example.yunus.ybazar_android;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import android.support.annotation.NonNull;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
public class all_product_list_ArrayAdapter extends ArrayAdapter<all_product_list_android_model> {
private final String Tag = "Filter" ;
private Context mContext;
private ArrayList<all_product_list_android_model> product_list ;
private final String urlMain = "http://118.179.70.235:28965/media/" ;
public all_product_list_ArrayAdapter(#NonNull Context context, ArrayList<all_product_list_android_model> list) {
super(context, 0, list);
mContext = context ;
product_list = list ;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
View listItem = convertView;
if(listItem == null)
listItem = LayoutInflater.from(mContext).inflate(R.layout.all_product_list_arrayadapter_connection,parent,false);
all_product_list_android_model product_list_to_show = product_list.get(position);
ImageView image = (ImageView)listItem.findViewById(R.id.product_image);
new DownLoadImage(image).execute(urlMain.concat(product_list_to_show.product_main_image));
TextView name = (TextView) listItem.findViewById(R.id.product_name_english);
name.setText(product_list_to_show.product_name_english);
TextView price = (TextView) listItem.findViewById(R.id.price);
price.setText(("Taka ")
.concat(product_list_to_show.product_unit_price)
.concat("/")
.concat(product_list_to_show.product_unit));
final Button bt = (Button) listItem.findViewById(R.id.add_to_cart);
bt.setTag(product_list_to_show.id);
final Button bt2 = (Button) listItem.findViewById(R.id.view_product);
bt2.setTag(product_list_to_show.id);
bt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
}
});
bt2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(mContext, indi_product_show.class);
intent.putExtra("product_id",String.valueOf(bt2.getTag()));
mContext.startActivity(intent);
}
});
return listItem;
}
}
Set your ListView's divider to null and its Divider Height to 0 pixels:
listView = (ListView) findViewById(R.id.product_list);
listView.setDivider(null);
listView.setDividerHeight(0);
mAdapter = new all_product_list_ArrayAdapter(all_product.this,data);
listView.setAdapter(mAdapter);
more info can be found in the docs for ListView here :
ListView#setDivider(android.graphics.drawable.Drawable)
ListView#setDividerHeight(int)
use divider for ListView in this way:
<ListView
android:id="#+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#null"
android:dividerHeight="0dp"/>

I/Choreographer: Skipped 38 frames

I'm starting to developing in Android and I was wondering if there is another way to change the font of the text.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.escena_1/* .activity_main*/);
/* IM USING THIS */
TextView tx = (TextView) findViewById(R.id.textViewx);
Typeface custom_font = Typeface.createFromAsset(getAssets(), "font/OpenSans-Light.ttf");
tx.setTypeface(custom_font);
}
}
Well, I don't have anything else besides that. But I'm getting the error "Skipped 38 frames".
thanks for the answers.
This is my mainactivity.java
package com.example.asus.app1;
import android.graphics.Typeface;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
public class MainActivity extends AppCompatActivity {
private GoogleApiClient client;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.escena_1/* .activity_main*/);
TextView tx = (TextView) findViewById(R.id.textViewx);
Typeface custom_font = Typeface.createFromAsset(getAssets(), "font/OpenSans-Light.ttf");
tx.setTypeface(custom_font);
TextView texto_2 = (TextView) findViewById(R.id.textView2);
texto_2.setTypeface(custom_font);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
/// client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
}
And this is mya "escena_1" xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
style="#android:style/Theme.Material.Light.Dialog.NoActionBar">
<ImageView
android:layout_width="130dp"
android:layout_height="130dp"
android:id="#+id/imageView"
android:layout_gravity="center"
android:src="#drawable/image_1"
android:contentDescription="#string/imagen_1"
android:focusable="true"
android:cropToPadding="false"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="83dp" />
<!--StayWithMe12!-->
<TextView
android:layout_width="206dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/text_1"
android:id="#+id/textViewx"
android:layout_gravity="center_horizontal|bottom"
android:gravity="top"
android:textIsSelectable="false"
android:textSize="33sp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/text_2"
android:id="#+id/textView2"
android:textSize="15sp"
android:textIsSelectable="false"
android:textAlignment="center"
android:textColor="#666666"
android:layout_below="#+id/textViewx"
android:layout_alignParentStart="true"
android:layout_marginTop="27dp" />
</RelativeLayout>`enter code here`

Null pointer exception while setting onClickListener on an imageView in a fragment class [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 7 years ago.
I am new to android and I am in a learning phase.I searched a lot but couldn't find an appropriate solution for this. I am getting a null pointer exception at notes.setOnClickListener though I have added findViewById statement
package com.example.hp.newcalendar;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
public class PreviouslyCalledFragment extends Fragment {
ListView students;
TextView test;
ImageView notes;
SimpleDateFormat formatter = new SimpleDateFormat("dd M yyyy hh:mm a");
String dateInString="23 Dec 2015 18:00 pm";
View view;
Context mContext;
ArrayList<FieldDetails> searchResults;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view = inflater.inflate(R.layout.activity_previously_called_fragment, container, false);
students = (ListView) view.findViewById(R.id.alreadyCalled);
notes=(ImageView)view.findViewById(R.id.notesView);
searchResults = GetSearchResults();
students.setAdapter(new CustomAdapter_Notes(mContext, searchResults));
notes.setOnClickListener(new View.OnClickListener() { //null pointer exception
#Override
public void onClick(View v) {
Toast.makeText(mContext,"hello", Toast.LENGTH_LONG).show();
}
});
return view;
}
#Override
public void onAttach(final Activity activity) {
super.onAttach(activity);
mContext = activity;
}
private ArrayList<FieldDetails> GetSearchResults() {
ArrayList<FieldDetails> results = new ArrayList<FieldDetails>();
FieldDetails fieldDetails = new FieldDetails();
fieldDetails.setName("Aman Jain");
fieldDetails.setTime("Dec 23,18:00 pm");
results.add(fieldDetails);
fieldDetails = new FieldDetails();
fieldDetails.setName("Keshav Sharma");
fieldDetails.setTime("Dec 23,19:00 pm");
results.add(fieldDetails);
return results;
}
}
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"
tools:context=".MainActivity"
android:padding="5dp"
android:background="#ffffff">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/alreadyCalled"
android:layout_centerHorizontal="true"
android:clickable="false"
android:layout_alignParentTop="true" />
Custom_layout xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:textSize="15dp"
android:id="#+id/nameOfInterviewee"
android:textColor="#008080"
android:layout_marginTop="5dp"
android:paddingBottom="5dp"
android:layout_marginLeft="2dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:textSize="12dp"
android:id="#+id/dateAndTime"
android:textColor="#008080"
android:paddingBottom="10dp"
android:layout_below="#+id/nameOfInterviewee"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="-5dp"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#848482"
android:id="#+id/view"
android:layout_below="#+id/dateAndTime"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="30dp"
android:layout_height="20dp"
android:id="#+id/notesView"
android:clickable="true"
android:layout_marginTop="16dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="#drawable/notes"/>
</RelativeLayout>
PLEASE HELP !!
This is most likely because R.id.notesView id is not present in your xml file R.layout.activity_previously_called_fragment. Please check the xml file or share it here.

how to display value of textbox on same screen in android application just like whatsaap

This is my main file where i am calling the click event on button to pass the value.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setTitle("aakash");
SetContentView(R.id.lst);
Button b = (Button) findViewById(R.id.sendbtn);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(android.view.View v) {
startActivity(new Intent(View.this,View.class));
}
});
}
**xml**
<?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:orientation="vertical"
android:background="#ffffff"
>
<TextView
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:textColor="#000000"
android:text="aakash"
android:background="#c0c0c0"
/>
<ScrollView
android:id="#+id/lst"
android:background="#fefefe"
android:layout_below="#+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom_holder"
>
</ScrollView>
<EditText
android:id="#+id/chattxt"
android:layout_width="230dp"
android:layout_height="45dp"
android:hint="type here"
android:inputType="textMultiLine" />
<Button
android:id="#+id/sendbtn"
android:layout_width="75dp"
android:layout_height="45dp"
android:text="Send" />
</LinearLayout>
I want the value of textbox to display on the same screen(scrollview)box and also i want to pass a httppost request to pass a value..plz help me out
Thnks in advance
I think, you can use a ListView insted of scroll view. and add list items from the chat text value dynamically.
call notifydatasetchanged() every time when you add a new item to it.
<TextView
android:id="#+id/username"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:textColor="#000000"
android:text="aakash"
android:background="#c0c0c0"
/>
<ListView
android:id="#+id/listView_chats"
android:layout_width="match_parent"
android:layout_height="100dp"
>
</ListView>
<EditText
android:id="#+id/chattxt"
android:layout_width="230dp"
android:layout_height="45dp"
android:hint="type here"
android:inputType="textMultiLine" />
<Button
android:id="#+id/sendbtn"
android:layout_width="75dp"
android:layout_height="45dp"
android:text="Send" />
</LinearLayout>
Write a custom adapter for the listView and add the code to manage the list data.
i got the answer to my question
import android.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class ButtonActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_button);
}
public void setText(){
Button myButton = (Button)findViewById(R.id.button1);
final TextView myText = (TextView)findViewById(R.id.text1);
final EditText myInput = (EditText)findViewById(R.id.edit);
myButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
myText.setText(myInput.getText());
}
});
}
}

Categories

Resources