I/Choreographer: Skipped 38 frames - android

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`

Related

app showing some irrelevant Text instead of a Textview

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.

how to make static expandabletextview to dynamic expandaletextview

I create a static expandaletextview in this example i used two Textview and two ImageButton so now how to i make this dynamic expandable..Any one can help me please because i m very new in android... Here below is my full static source code thanks in advance
MainActivity class
package com.example.atextalignment;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView descText;
ImageButton show, hide;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
descText = (TextView) findViewById(R.id.description_text);
show = (ImageButton) findViewById(R.id.show);
show.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("Show button");
show.setVisibility(View.INVISIBLE);
hide.setVisibility(View.VISIBLE);
descText.setMaxLines(Integer.MAX_VALUE);
}
});
hide = (ImageButton) findViewById(R.id.hide);
hide.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("Hide button");
hide.setVisibility(View.INVISIBLE);
show.setVisibility(View.VISIBLE);
descText.setMaxLines(5);
}
});
}
}
my Xml layout
<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="com.example.atextalignment.Second" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<TextView
android:id="#+id/description_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:maxLines="5"
android:text="#string/desc_content" />
<ImageButton
android:id="#+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/description_text"
android:background="#android:color/transparent"
android:clickable="true"
android:src="#drawable/ic_launcher"/>
<ImageButton
android:id="#+id/hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/description_text"
android:clickable="true"
android:src="#drawable/ic_launcher"
android:visibility="invisible" />
</RelativeLayout>
String.xml
<string name="desc_content"> Android powers hundreds of millions of mobile devices in more than 190 countries around the world. It\'s the largest installed base of any mobile platform and growing fast—every day another million users power up their Android devices for the first time and start looking for apps, games, and other digital content.
Android gives you a world-class platform for creating apps and games for Android users everywhere, as well as an open marketplace for distributing to them instantly.
</string>

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());
}
});
}
}

Getting value from dynamically created textview in android

MainActivity's code
How can I get values from the text boxes and the qty box in that user will input the value. price will come from server and than i want to calculate the bill and show it in next layout. plz give me some easy explanation as i am not expert in it. thanks in advance.
MainActivity .java
package com.example.myone;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
EditText textIn;
Button buttonAdd;
LinearLayout container;
private Button done;
private TextView tv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textIn = (EditText)findViewById(R.id.textin);
buttonAdd = (Button)findViewById(R.id.add);
container = (LinearLayout)findViewById(R.id.container);
done = (Button) findViewById(R.id.cal);
tv= (TextView) findViewById(R.id.tv);
buttonAdd.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
LayoutInflater layoutInflater =
(LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.row, null);
TextView textOut = (TextView)addView.findViewById(R.id.textout);
textOut.setText(textIn.getText().toString());
//(int1);
Button buttonRemove = (Button)addView.findViewById(R.id.remove);
buttonRemove.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
((LinearLayout)addView.getParent()).removeView(addView);
}});
container.addView(addView);
}});
}
}
MainActivity.xml
<LinearLayout
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"
android:orientation="vertical"
android:background="#drawable/mainbg"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/textin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter your item here"
/>
<Button
android:id="#+id/cal"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/textin"
android:text="Done!"
android:layout_alignParentLeft="true"
/>
<Button
android:id="#+id/add"
android:text="Add"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignBaseline="#+id/cal"
/>
</RelativeLayout>
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
Row.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#drawable/borderbg"
android:orientation="horizontal"
android:id="#+id/rel"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textout"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:hint="Item"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
/>
<EditText
android:id="#+id/qty"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignTop="#+id/price"
android:layout_toRightOf="#+id/price"
android:layout_marginLeft="50dp"
android:textSize="12sp"
android:hint="Qty" />
<TextView
android:id="#+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textout"
android:layout_alignBottom="#+id/textout"
android:layout_marginLeft="42dp"
android:layout_toRightOf="#+id/textout"
android:hint="Price" />
<Button
android:id="#+id/remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="left"
android:text="remove" />
</RelativeLayout>
Simply I want to create a basic shopping app that have 20 products. the price and product name will come from server and quantity will input by user so how do I that?
You are looking for something like this
int count = container.getChildCount();
for (int i = 0; i < count; i++) {
final View row = container.getChildAt(i);
TextView textOut = (TextView)row.findViewById(R.id.textout);
String data = textOut.getText().toString();
}
Where container is your LinearLayout in which you have added your inflated rows.
Try this:-
To take user input from text box:-
int qty = Integer.parseInt(qtyTextBox.getText().toString());
Caluculate bill:-
double bill = price*qty;
Send bill value to next activity:-
Intent in = new Intent();
in.putExtra("Bill", bill);
startActivity(in);
Get bill value in next activity:-
Intent in = getIntent();
int mBill = in.getExtra("Bill");
string bill = String.valueOf(mBill);
Now you can set the value of 'bill' to the TextView where you want to display it.

Android Development Button

I am learning to make android apps and I have a problem with my hello world programs buttons.
Here's my code:
package com.Norwood.helloandroid; import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android.");
setContentView(tv);
}
public void onclick01(View View)
{
Toast.makeText(this, "Will change in 1.2", Toast.LENGTH_SHORT).show();
}
public void onclick02(View View)
{
Toast.makeText(this, "Will change in 1.2", Toast.LENGTH_SHORT).show();
}
}
And my XML file:
<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" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world"
android:textSize="60sp" />
<Button
android:id="#+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:minHeight="92sp"
android:onClick="onclick01"
android:text="#string/ChangeCoulour"
android:textSize="22sp" />
<Button
android:id="#+id/Button02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:minHeight="92sp"
android:onClick="onclick02"
android:text="#string/Change_Text_Colour"
android:textSize="22sp" />
</RelativeLayout>
But when I run the app both on the emulator and on my android the buttons don't show up.
And they show up in the graphical layout of the XML file.
Thanks
Collin N.
try:
setContentView(R.layout.yourXml)
You cannot do it your way because you must set your view to your xml first. have setContentview on the line after onCreate
TextView tv = new TextView(this);
tv.setText("Hello, Android.");
setContentView(tv);//wrong
reply to comment:
Like this:
public class MainActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.YOUR_XML_FILE_NAME);
TextView tv = new TextView(this);
tv.setText("Hello, Android.");
}

Categories

Resources