Hello all, I have problem in I developing a program for learning purposes also for my school. So here is the code, also my code not completed so there any problem please write how to fix
Code:
package com.leftas.vidurkioskaiciavimas;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.TextView;
public class vidurkioskaiciuokle extends Activity {
int c;
TextView mUserOutput,mUserInput;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vidurkio_skaiciuokle);
TextView mUserOutput = (TextView) findViewById(R.id.textView2);
TextView mUserInput = (TextView) findViewById(R.id.textView);
}
private void buttonEventHandler(View v) {
switch(v.getId()) {
case R.id.button1 :
mUserInput.setText(mUserInput.getText() + "1");
c = +1;
break;
case R.id.button2 :
mUserInput.setText(mUserInput.getText() + "2");
c = +2;
break;
case R.id.button3 :
mUserInput.setText(mUserInput.getText() + "3");
c = +3;
break;
case R.id.button4 :
mUserInput.setText(mUserInput.getText() + "4");
c = +4;
break;
case R.id.button5 :
mUserInput.setText(mUserInput.getText() + "5");
c = +5;
break;
case R.id.button6 :
mUserInput.setText(mUserInput.getText() + "6");
c = +6;
break;
case R.id.button7 :
mUserInput.setText(mUserInput.getText() + "7");
c = +7;
break;
case R.id.button8 :
mUserInput.setText(mUserInput.getText() + "8");
c = +8;
break;
case R.id.button9 :
mUserInput.setText(mUserInput.getText() + "9");
c = +9;
break;
case R.id.button10 :
mUserInput.setText(mUserInput.getText() + "10");
c = +10;
break;
}
}
public void computeAverage(int [] scores)
{
double average = 0;
for (int c : scores) {
average += c;
}
average /= scores.length;
mUserOutput.setText(Double.toString(average));
}
}
So when I press 1,2,3,4,5,6,7,8,9,10 it doesn't change any text..
Also if this not Q&A Forum please move it(Report it) Because I searched where i can post and only found here
My solution
Code:
mUserOutput = (TextView) findViewById(R.id.textView2);
mUserInput = (TextView) findViewById(R.id.textView);
Could you please post your xml file, too?
What happens if you add this to the switch statement?
Code:
default:
Log.d("switch", "default");
break;
Do you see it in the logs?
Btw, it is the right subforum.
Nothing happens, even message doesn't appear.
Xml file:
Code:
<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=".vidurkioskaiciuokle">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/button1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/button2"
android:layout_alignTop="@+id/button1"
android:layout_toRightOf="@+id/button1" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/button3"
android:layout_alignBottom="@+id/button2"
android:layout_toRightOf="@+id/button2" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:id="@+id/button4"
android:layout_alignTop="@+id/button3"
android:layout_toRightOf="@+id/button3" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/button5"
android:layout_alignTop="@+id/button4"
android:layout_toRightOf="@+id/button4" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:id="@+id/button6"
android:layout_alignTop="@+id/button5"
android:layout_toRightOf="@+id/button5" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:id="@+id/button7"
android:layout_alignBottom="@+id/button6"
android:layout_toRightOf="@+id/button6" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="@+id/button8"
android:layout_alignTop="@+id/button9"
android:layout_toLeftOf="@+id/button9" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="@+id/button9"
android:layout_above="@+id/button2"
android:layout_toLeftOf="@+id/button3" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:id="@+id/button10"
android:layout_alignTop="@+id/button9"
android:layout_toRightOf="@+id/button9" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/textView"
android:layout_above="@+id/textView2"
android:layout_alignRight="@+id/textView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false"
android:layout_alignWithParentIfMissing="false"
android:layout_above="@+id/button8"
android:layout_toLeftOf="@+id/button7"
android:layout_alignLeft="@+id/button8" />
</RelativeLayout>
Paulius7 said:
Nothing happens, even message doesn't appear.
Xml file:
Code:
<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=".vidurkioskaiciuokle">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/button1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/button2"
android:layout_alignTop="@+id/button1"
android:layout_toRightOf="@+id/button1" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/button3"
android:layout_alignBottom="@+id/button2"
android:layout_toRightOf="@+id/button2" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:id="@+id/button4"
android:layout_alignTop="@+id/button3"
android:layout_toRightOf="@+id/button3" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/button5"
android:layout_alignTop="@+id/button4"
android:layout_toRightOf="@+id/button4" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:id="@+id/button6"
android:layout_alignTop="@+id/button5"
android:layout_toRightOf="@+id/button5" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:id="@+id/button7"
android:layout_alignBottom="@+id/button6"
android:layout_toRightOf="@+id/button6" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="@+id/button8"
android:layout_alignTop="@+id/button9"
android:layout_toLeftOf="@+id/button9" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="@+id/button9"
android:layout_above="@+id/button2"
android:layout_toLeftOf="@+id/button3" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:id="@+id/button10"
android:layout_alignTop="@+id/button9"
android:layout_toRightOf="@+id/button9" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/textView"
android:layout_above="@+id/textView2"
android:layout_alignRight="@+id/textView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false"
android:layout_alignWithParentIfMissing="false"
android:layout_above="@+id/button8"
android:layout_toLeftOf="@+id/button7"
android:layout_alignLeft="@+id/button8" />
</RelativeLayout>
Click to expand...
Click to collapse
Ah, add this to all buttons:
Code:
android:[U][/U]onClick="buttonEventHandler"
Hello again, now my program crash(Force Close) when I press one of buttons.
updated code
Code:
package com.leftas.vidurkioskaiciavimas;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
public class vidurkioskaiciuokle extends Activity {
int c;
TextView mUserOutput,mUserInput;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vidurkio_skaiciuokle);
TextView mUserOutput = (TextView) findViewById(R.id.textView2);
TextView mUserInput = (TextView) findViewById(R.id.textView);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.vidurkioskaiciuokle, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.about:
startActivity(new Intent(this, About.class));
return true;
case R.id.exit:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void buttonEventHandler(View v) {
switch(v.getId()) {
case R.id.button1 :
mUserInput.setText(mUserInput.getText() + "1");
c = +1;
break;
case R.id.button2 :
mUserInput.setText(mUserInput.getText() + "2");
c = +2;
break;
case R.id.button3 :
mUserInput.setText(mUserInput.getText() + "3");
c = +3;
break;
case R.id.button4 :
mUserInput.setText(mUserInput.getText() + "4");
c = +4;
break;
case R.id.button5 :
mUserInput.setText(mUserInput.getText() + "5");
c = +5;
break;
case R.id.button6 :
mUserInput.setText(mUserInput.getText() + "6");
c = +6;
break;
case R.id.button7 :
mUserInput.setText(mUserInput.getText() + "7");
c = +7;
break;
case R.id.button8 :
mUserInput.setText(mUserInput.getText() + "8");
c = +8;
break;
case R.id.button9 :
mUserInput.setText(mUserInput.getText() + "9");
c = +9;
break;
case R.id.button10 :
mUserInput.setText(mUserInput.getText() + "10");
c = +10;
break;
case R.id.buttonclear :
mUserOutput.setText(null);
mUserInput.setText(null);
c = 0;
double average = 0;
}
}
public void computeAverage(int [] scores)
{
double average = 0;
for (int c : scores) {
average += c;
}
average /= scores.length;
mUserOutput.setText(Double.toString(average));
}
}
Xml File
Code:
<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=".vidurkioskaiciuokle">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/button1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/button2"
android:layout_alignTop="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/button3"
android:layout_alignBottom="@+id/button2"
android:layout_toRightOf="@+id/button2"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:id="@+id/button4"
android:layout_alignTop="@+id/button3"
android:layout_toRightOf="@+id/button3"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/button5"
android:layout_alignTop="@+id/button4"
android:layout_toRightOf="@+id/button4"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:id="@+id/button6"
android:layout_alignTop="@+id/button5"
android:layout_toRightOf="@+id/button5"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:id="@+id/button7"
android:layout_above="@+id/button2"
android:layout_toRightOf="@+id/button2"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="@+id/button8"
android:layout_alignTop="@+id/button9"
android:layout_toLeftOf="@+id/button9"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="@+id/button9"
android:layout_above="@+id/button2"
android:layout_toLeftOf="@+id/button3"
android:onClick="buttonEventHandler" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:id="@+id/button10"
android:layout_above="@+id/button4"
android:layout_toLeftOf="@+id/button5"
android:onClick="buttonEventHandler" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/textView"
android:layout_above="@+id/textView2"
android:layout_alignParentRight="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false"
android:layout_alignWithParentIfMissing="false"
android:layout_above="@+id/button8"
android:layout_alignLeft="@+id/button8"
android:layout_alignRight="@+id/textView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"
android:id="@+id/buttonclear"
android:layout_above="@+id/button5"
android:layout_alignRight="@+id/button6"
android:layout_alignLeft="@+id/button5"
android:onClick="buttonEventHandler" />
</RelativeLayout>
Your buttonEventHandler method needs to be public.
Still Force Close even Public void. Also When I go to "About" also crash
Code:
package com.leftas.vidurkioskaiciavimas;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.leftas.vidurkioskaiciavimas.vidurkioskaiciuokle;
public class About extends Activity implements View.OnClickListener {
TextView bug ;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
bug = (TextView)findViewById(R.id.textViewbug);
bug.setOnClickListener(this);
}
private String bugReport = "Description\n" + "===========\n" + "Enter Your Problem" + "\n" + "\nAdditional Info\n" + "===========\n" + "App version: "
+ "1.0" + "Device: " + Build.MODEL + "\n" + "Android version: " + Build.VERSION.RELEASE + "\n" + "Firmware fingerprint: " + Build.FINGERPRINT + "\n";
public void onClick(View v) {
Intent gmail = new Intent(Intent.ACTION_VIEW);
gmail.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
gmail.putExtra(Intent.EXTRA_EMAIL, new String[] { "..." });
gmail.setData(Uri.parse("..."));
gmail.putExtra(Intent.EXTRA_SUBJECT, "Bug Report: Vidurkio Skaičiavimas");
gmail.setType("plain/text");
gmail.putExtra(Intent.EXTRA_TEXT, bugReport);
startActivity(gmail);
}
}
Xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Kurėjas:Paulius Karlonas(Leftas)"
android:id="@+id/textView"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="El.Paštas:...."
android:id="@+id/textView2"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Radai Klaidų ? Rašyk"
android:id="@+id/textViewbug"
android:layout_gravity="center"
android:clickable="true"
android:onClick="onClick" />
</LinearLayout>
It's Lithuanian Language, So you could don't understand that
Paulius7 said:
Still Force Close even Public void. Also When I go to "About" also crash
Code:
package com.leftas.vidurkioskaiciavimas;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.leftas.vidurkioskaiciavimas.vidurkioskaiciuokle;
public class About extends Activity implements View.OnClickListener {
TextView bug ;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
bug = (TextView)findViewById(R.id.textViewbug);
bug.setOnClickListener(this);
}
private String bugReport = "Description\n" + "===========\n" + "Enter Your Problem" + "\n" + "\nAdditional Info\n" + "===========\n" + "App version: "
+ "1.0" + "Device: " + Build.MODEL + "\n" + "Android version: " + Build.VERSION.RELEASE + "\n" + "Firmware fingerprint: " + Build.FINGERPRINT + "\n";
public void onClick(View v) {
Intent gmail = new Intent(Intent.ACTION_VIEW);
gmail.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
gmail.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
gmail.setData(Uri.parse("[email protected]"));
gmail.putExtra(Intent.EXTRA_SUBJECT, "Bug Report: John Doe");
gmail.setType("plain/text");
gmail.putExtra(Intent.EXTRA_TEXT, bugReport);
startActivity(gmail);
}
}
Xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Kurėjas:Paulius Karlonas(Leftas)"
android:id="@+id/textView"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="[email protected]"
android:id="@+id/textView2"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Radai Klaidų ? Rašyk"
android:id="@+id/textViewbug"
android:layout_gravity="center"
android:clickable="true"
android:onClick="onClick" />
</LinearLayout>
It's Lithuanian Language, So you could don't understand that
Click to expand...
Click to collapse
Please post a logcat. (Just the part with the crash.)
We need the information in it to help you.
---------- Post added at 12:39 PM ---------- Previous post was at 12:36 PM ----------
In the second example you already set a listener:
Code:
bug.setOnClickListener(this);
So no need for
Code:
android:[B][/B]onClick
Problem is that I am programming in my phone with aide. I can see logcat but I can't copy it... maybe you know how to debug from ?
Sent from my GT-I9100 using Tapatalk 4
Paulius7 said:
Problem is that I am programming in my phone with aide. I can see logcat but I can't copy it... maybe you know how to debug from ?
Sent from my GT-I9100 using Tapatalk 4
Click to expand...
Click to collapse
I developed with AIDE, too. I always used aLogcat for that.
nikwen said:
I developed with AIDE, too. I always used aLogcat for that.
Click to expand...
Click to collapse
Now build with aide and even not start in Windows developing with android studio
Code:
I/PackageManager( 2911): Package com.leftas.vidurkioskaiciavimas codePath changed from /data/app/com.leftas.vidurkioskaiciavimas-2.apk to /data/app/com.leftas.vidurkioskaiciavimas-1.apk; Retaining data and using new
E/AndroidRuntime(26441): java.lang.RuntimeException: Unable to instantiate application com.leftas.vidurkioskaiciavimas.ApplicationContextProvider: java.lang.ClassNotFoundException: com.leftas.vidurkioskaiciavimas.ApplicationContextProvider
E/AndroidRuntime(26441): Caused by: java.lang.ClassNotFoundException: com.leftas.vidurkioskaiciavimas.ApplicationContextProvider
I/ActivityManager( 2911): Process com.leftas.vidurkioskaiciavimas (pid 26441) (adj 9) has died.
when I will be with pc will try to build and save logcat then.
Sent from my GT-I9100 using Tapatalk 4
Sorry for double post...
Button logcat
Code:
E/AndroidRuntime( 3887): at com.leftas.vidurkioskaiciavimas.vidurkioskaiciuokle.buttonEventHandler(vidurkioskaiciuokle.java:96)
I/ActivityManager( 2911): Process com.leftas.vidurkioskaiciavimas (pid 3887) (adj 1) has died.
I/Icing.InternalIcingCorporaProvider( 4100): Updating corpora: A: com.leftas.vidurkioskaiciavimas, C: MAYBE
D/PackageAddedReceiver( 856): package added com.leftas.vidurkioskaiciavimas
Android Studio
Code:
09-01 17:35:06.414 5616-5616/com.leftas.vidurkioskaiciavimas W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41b202a0)
09-01 17:35:06.442 5616-5616/com.leftas.vidurkioskaiciavimas E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3704)
at android.view.View.performClick(View.java:4232)
at android.view.View$PerformClick.run(View.java:17298)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3699)
... 11 more
Caused by: java.lang.NullPointerException
at com.leftas.vidurkioskaiciavimas.vidurkioskaiciuokle.buttonEventHandler(vidurkioskaiciuokle.java:96)
... 14 more
"About" I was didin't declarate in AndroidManifest
Paulius7 said:
Sorry for double post...
Button logcat
Code:
E/AndroidRuntime( 3887): at com.leftas.vidurkioskaiciavimas.vidurkioskaiciuokle.buttonEventHandler(vidurkioskaiciuokle.java:96)
I/ActivityManager( 2911): Process com.leftas.vidurkioskaiciavimas (pid 3887) (adj 1) has died.
I/Icing.InternalIcingCorporaProvider( 4100): Updating corpora: A: com.leftas.vidurkioskaiciavimas, C: MAYBE
D/PackageAddedReceiver( 856): package added com.leftas.vidurkioskaiciavimas
Android Studio
Code:
09-01 17:35:06.414 5616-5616/com.leftas.vidurkioskaiciavimas W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41b202a0)
09-01 17:35:06.442 5616-5616/com.leftas.vidurkioskaiciavimas E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3704)
at android.view.View.performClick(View.java:4232)
at android.view.View$PerformClick.run(View.java:17298)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3699)
... 11 more
Caused by: java.lang.NullPointerException
at com.leftas.vidurkioskaiciavimas.vidurkioskaiciuokle.buttonEventHandler(vidurkioskaiciuokle.java:96)
... 14 more
"About" I was didin't declarate in AndroidManifest
Click to expand...
Click to collapse
Is that the logcat for the clear button? If it is, this might be the solution:
Replace
Code:
mUserOutput.setText(null);
mUserInput.setText(null);
by
Code:
mUserOutput.setText("");
mUserInput.setText("");
There should be a different logcat for the other buttons though.
Clear Button
Android Studio
Code:
4590-4590/com.leftas.vidurkioskaiciavimas E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3704)
at android.view.View.performClick(View.java:4232)
at android.view.View$PerformClick.run(View.java:17298)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3699)
... 11 more
Caused by: java.lang.NullPointerException
at com.leftas.vidurkioskaiciavimas.vidurkioskaiciuokle.buttonEventHandler(vidurkioskaiciuokle.java:101)
... 14 more
ALogCat
Code:
E/AndroidRuntime( 2599): at com.leftas.vidurkioskaiciavimas.vidurkioskaiciuokle.buttonEventHandler(vidurkioskaiciuokle.java:101)
I/ActivityManager( 2911): Process com.leftas.vidurkioskaiciavimas (pid 2599) (adj 1) has died.
10
6531-6531/com.leftas.vidurkioskaiciavimas E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3704)
at android.view.View.performClick(View.java:4232)
at android.view.View$PerformClick.run(View.java:17298)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3699)
... 11 more
Caused by: java.lang.NullPointerException
at com.leftas.vidurkioskaiciavimas.vidurkioskaiciuokle.buttonEventHandler(vidurkioskaiciuokle.java:96)
... 14 more
Click to expand...
Click to collapse
ALogCat
Code:
E/AndroidRuntime( 6531): at com.leftas.vidurkioskaiciavimas.vidurkioskaiciuokle.buttonEventHandler(vidurkioskaiciuokle.java:96)
All codes same just change : "number" of their line ...
Could you please tell me which line it is? (I mean the line in the source code, not just the number.)
"Clear"
Code:
mUserOutput.setText("");
"10"
Code:
mUserInput.setText(mUserInput.getText() + "10");
If you want that ?
Paulius7 said:
"Clear"
Code:
mUserOutput.setText("");
"10"
Code:
mUserInput.setText(mUserInput.getText() + "10");
If you want that ?
Click to expand...
Click to collapse
Yes, that's what I wanted. Thanks. :good:
That means that both TextViews are null. I guess that the Activity cannot find them.
Do you get a output in the logs if you replace your onCreate method with this:
Code:
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.vidurkio_skaiciuokle);
TextView mUserOutput = (TextView) findViewById(R.id.textView2);
TextView mUserInput = (TextView) findViewById(R.id.textView);
if (mUserOutput == null)
Log.e("output", null);
if (mUserInput == null)
Log.e("input", null);
}
---------- Post added at 10:13 PM ---------- Previous post was at 10:11 PM ----------
Oh, just saw a big mistake:
You always use @+id/...
However, @+id is just used to introduce new ids in the android:id attribute.
In all other cases use @id/ (without the +).
---------- Post added at 10:15 PM ---------- Previous post was at 10:13 PM ----------
One example (needs to be fixed for all views):
Code:
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/textView"
android:layout_above="[COLOR="Red"]@id[/COLOR]/textView2"
android:layout_alignRight="[COLOR="Red"]@id[/COLOR]/textView2" />
Fixed:
Code:
mUserOutput = (TextView) findViewById(R.id.textView2);
mUserInput = (TextView) findViewById(R.id.textView);
But now problem that don't change text(Input works but Output just don't output anything)
Code:
public void computeAverage(int [] c)
{
double average = 0;
for (int i = 0; i < c.length; i++)
{
average += c[i];
Log.d("TAG", "Average calculated");
}
average /= c.length;
mUserOutput.setText(Double.toString(average));
Log.d("TAG", "Showing average");
}
No log, too.
But output works
Code:
case R.id.button3 :
mUserInput.setText(mUserInput.getText() + "3" + "+");
mUserOutput.setText("3.0");
c = +3;
break;
It changes text.
I know that is nothing calling computeAverage how to do that when I click 10(It show only 10) and 9(It show 9.5 in output) that show mean(9.5) of these numbers ?
Paulius7 said:
Fixed:
Code:
mUserOutput = (TextView) findViewById(R.id.textView2);
mUserInput = (TextView) findViewById(R.id.textView);
But now problem that don't change text(Input works but Output just don't output anything)
Code:
public void computeAverage(int [] c)
{
double average = 0;
for (int i = 0; i < c.length; i++)
{
average += c[i];
Log.d("TAG", "Average calculated");
}
average /= c.length;
mUserOutput.setText(Double.toString(average));
Log.d("TAG", "Showing average");
}
No log, too.
But output works
Code:
case R.id.button3 :
mUserInput.setText(mUserInput.getText() + "3" + "+");
mUserOutput.setText("3.0");
c = +3;
break;
It changes text.
I know that is nothing calling computeAverage how to do that when I click 10(It show only 10) and 9(It show 9.5 in output) that show mean(9.5) of these numbers ?
Click to expand...
Click to collapse
You need to cast the length to double:
Code:
public void computeAverage(int [] c)
{
double average = 0;
for (int i = 0; i < c.length; i++)
{
average += c[i];
Log.d("TAG", "Average calculated");
}
average /= ((double) c.length);
mUserOutput.setText(Double.toString(average));
Log.d("TAG", "Showing average");
}
For question #2:
Add another field "lastNumber" of type double to your class:
Code:
double lastNumber = -1;
Then do this in onClick:
Code:
case R.id.button3 :
c = +3;
if (lastNumber == -1) {
mUserInput.setText(mUserInput.getText() + "3" + "+");
mUserOutput.setText("3.0");
lastNumber = 3;
} else {
//call your computeAverageMethod here
lastNumber = 3;
}
break;
My question just one, How to make that computeAverage will work ? because now none calling him so it's give no result(It don't change text when I click on buttons :/)
About Question #2 I just showed that mUserOutput works
My English sucks.....
Related
I am in the process of learning android development and am trying to understand how to use compound controls.
Here is the control I have created:
Code:
package net.iamcorbin.dialer;
public class DialPadView extends LinearLayout implements OnClickListener {
Button buttons[];
TextView display;
public DialPadView(Context context) {
super(context);
String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li;
li = (LayoutInflater)getContext().getSystemService(infService);
li.inflate(R.layout.dialpad, this, true);
this.display = (TextView)findViewById(R.id.displayNumber);
this.display.setText("Dial a Number");
this.buttons[0] = (Button)findViewById(R.id.button0);
this.buttons[1] = (Button)findViewById(R.id.button1);
this.buttons[2] = (Button)findViewById(R.id.button2);
this.buttons[3] = (Button)findViewById(R.id.button3);
this.buttons[4] = (Button)findViewById(R.id.button4);
this.buttons[5] = (Button)findViewById(R.id.button5);
this.buttons[6] = (Button)findViewById(R.id.button6);
this.buttons[7] = (Button)findViewById(R.id.button7);
this.buttons[8] = (Button)findViewById(R.id.button8);
this.buttons[9] = (Button)findViewById(R.id.button9);
this.buttons[10] = (Button)findViewById(R.id.buttonStar);
this.buttons[11] = (Button)findViewById(R.id.buttonPound);
for(Button button : this.buttons) {
button.setOnClickListener(this);
}
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.button0:
this.display.append("0");
break;
case R.id.button1:
this.display.append("1");
break;
case R.id.button2:
this.display.append("2");
break;
case R.id.button3:
this.display.append("3");
break;
case R.id.button4:
this.display.append("4");
break;
case R.id.button5:
this.display.append("5");
break;
case R.id.button6:
this.display.append("6");
break;
case R.id.button7:
this.display.append("7");
break;
case R.id.button8:
this.display.append("8");
break;
case R.id.button9:
this.display.append("9");
break;
case R.id.buttonStar:
this.display.append("*");
break;
case R.id.buttonPound:
this.display.append("#");
break;
}
}
}
I don't really understand how to add this to my main layout. I thought you could add it in xml with a node like:
Code:
<net.iamcorbin.dialer.DialPadView android:id="+id/dialpad" /> (forum would not let me post the "at" symbol here, thought I was trying to post a link)
but adding this line causes the program to crash upon loading.
I figure I'm just making a stupid beginner mistake, could someone please correct me?
Thanks,
~Corbin
can anyone help? I am really eager to move forward with development, but I'm still stuck trying to get custom compound controls working.
I've been consulting the documentation(developer.android.com/guide/topics/ui/custom-components.html#compound) and if I change the main.xml to this:
Code:
<LinearLayout
class="net.iamcorbin.dialer.DialPadView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
the application runs but the custom DialPadView is no where to be found
Here is the dialpad.xml file:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="schemas.android.com/apk/res/android" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="+id/displayNumber" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="40dp">
<Button android:id="+id/button1" android:text="string/button1"
android:layout_width="fill_parent" android:layout_height="fill_parent"></Button>
<Button android:id="+id/button2" android:text="string/button2"
android:layout_width="fill_parent" android:layout_height="fill_parent"></Button>
<Button android:id="+id/button3" android:text="string/button3"
android:layout_width="fill_parent" android:layout_height="fill_parent"></Button>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="40dp">
<Button android:id="+id/button4" android:text="string/button4"
android:layout_width="fill_parent" android:layout_height="fill_parent"></Button>
<Button android:id="+id/button5" android:text="string/button5"
android:layout_width="fill_parent" android:layout_height="fill_parent"></Button>
<Button android:id="+id/button6" android:text="string/button6"
android:layout_width="fill_parent" android:layout_height="fill_parent"></Button>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="40dp">
<Button android:id="+id/button7" android:text="string/button7"
android:layout_width="fill_parent" android:layout_height="fill_parent"></Button>
<Button android:id="+id/button8" android:text="string/button8"
android:layout_width="fill_parent" android:layout_height="fill_parent"></Button>
<Button android:id="+id/button9" android:text="string/button8"
android:layout_width="fill_parent" android:layout_height="fill_parent"></Button>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="40dp">
<Button android:id="+id/buttonStar" android:text="string/buttonStar"
android:layout_width="fill_parent" android:layout_height="fill_parent"></Button>
<Button android:id="+id/button0" android:text="string/button0"
android:layout_width="fill_parent" android:layout_height="fill_parent"></Button>
<Button android:id="+id/buttonPound" android:text="string/buttonPound"
android:layout_width="fill_parent" android:layout_height="fill_parent"></Button>
</LinearLayout>
</LinearLayout>
("at" symbols removed)
I also just tried loading the dialpad.xml layout as the main layout just to make sure there were no errors being thrown there.
Code:
setContentView(R.layout.dialpad);
loaded just fine.
[SOLVED]
Oops...it was all a stupid java mistake:
Code:
Button buttons[];
changed to
Code:
Button buttons[] = new Button[12];
fixed the problem
Hi,
I am new to android development. I am facing problem in switching between activities. I am attaching the code files ... Please help me solve this problem
Being a new user the Forum doesn't allow me to write atTheRateSign in my message ... I am replacing it with % sign. Please don't confuse it.
Main Activity:
Code:
package swz.pkg;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class SWMainActivity extends Activity {
/** Called when the activity is first created. */
%Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnMSrch = (Button) findViewById(R.id.btnClosetSearch);
try{
btnMSrch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(),ClosetSearchAct.class);
startActivityForResult(myIntent,0);
}
});
}
catch (Exception ex)
{
System.out.println("---------------------******------------------------");
ex.printStackTrace();
System.out.println();
System.out.println("---------------------******------------------------");
}
}
}
main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="%+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="ht ... android"
>
<Button
android:id="%+id/btnMeasurementSearch"
android:layout_width="fill_parent"
android:layout_height="150px"
android:background="#ffffffff"
android:text="Measurement Search"
android:textSize="26sp"
android:typeface="serif"
android:textStyle="bold"
android:textColor="#ff8c2528"
android:layout_x="0px"
android:layout_y="47px"
>
</Button>
<Button
android:id="%+id/btnClosetSearch"
android:layout_width="fill_parent"
android:layout_height="150px"
android:text="Closet Search"
android:textSize="26sp"
android:typeface="serif"
android:textStyle="bold"
android:textColor="#ff462556"
android:layout_x="0px"
android:layout_y="213px"
>
</Button>
</AbsoluteLayout>
closetSearch activity(The next activity I want to move to):
Code:
package swz.pkg;
import android.app.Activity;
import android.os.Bundle;
public class ClosetSearchAct extends Activity {
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.closetsearchact);
}
}
closetsearchact.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="%+id/widget1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="ht .... android"
>
<Spinner
android:id="%+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="33px"
>
</Spinner>
<Spinner
android:id="%+id/spinner2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="101px"
>
</Spinner>
<Spinner
android:id="%+id/spinner3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="173px"
>
</Spinner>
<ImageButton
android:id="%+id/btnReg"
android:layout_width="128px"
android:layout_height="wrap_content"
android:src="%drawable/reg"
android:layout_x="151px"
android:layout_y="279px"
>
</ImageButton>
<ImageButton
android:id="%+id/btnSearch"
android:layout_width="114px"
android:layout_height="49px"
android:src="%drawable/search"
android:layout_x="37px"
android:layout_y="279px"
>
</ImageButton>
</AbsoluteLayout>
AndroidManifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="ht ... android"
package="swz.pkg"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="%drawable/icon" android:label="%string/app_name">
<activity android:name=".SWMainActivity"
android:label="%string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ClosetSearchAct" android:label="%string/app_name"> </activity>
</application>
</manifest>
Hi , i'm studyng android Adapter
I want create a ListView with a serie of data. Ok , the code.
Code:
/*
Activity class
*/
package it.actiondesign.android.app.userdata;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
public class UserDataActivity extends Activity {
ArrayList<UserData> allUsers = new ArrayList<UserData>();
private ListView myListView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myListView= (ListView) findViewById(R.id.datalist);
createFakeData();
int resID = R.layout.user_row;
// data_adpater = new ArrayAdapter<UserData>(this, R.layout.user_row, allUsers);
// myListView.setAdapter(data_adpater);
}
//fill ArrayList with fake data
private void createFakeData() {
UserData first = new UserData("Frank", "Smith", 30, "Chicaco");
UserData second = new UserData("Tania", "Roger", 20, "Los Angeles");
allUsers.add(first);
allUsers.add(second);
}
}
here the main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/datalist"></ListView>
</LinearLayout>
I create a class of data
Code:
public class UserData {
private String name;
private String surname;
private int age;
private String from;
public UserData(String _name , String _surname, int _age, String _from){
this.name= _name;
this.surname= _surname;
this.age= _age;
this.from= _from;
}
public String getName(){
return name;
}
public String getSurname(){
return surname;
}
public int getAge(){
return age;
}
public String getFrom(){
return from;
}
}
custom layout of a single item
Code:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="Name: "
android:id="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView android:text=""
android:id="@+id/tName" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="@color/red">
</TextView>
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="Surname: "
android:id="@+id/TextView02" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView android:text=""
android:id="@+id/tSurname" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="@color/red">
</TextView>
</TableRow>
<TableRow android:id="@+id/TableRow03" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="From: "
android:id="@+id/TextView03" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView android:text=""
android:id="@+id/tFrom" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="@color/red">
</TextView>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="Age: "
android:id="@+id/TextView03" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView android:text=""
android:id="@+id/tAge" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="@color/red">
</TextView>
</TableRow>
</TableLayout>
In other layout a create a ArrayAdpater<String> and all was simple, but how can fill TextView (tName, tSurname, tAge, tFrom) with data.
Now I use a simple ArrayList after i load data from WebService
Depends what kind of data your are retrieving. In your layout you have 4 textview 'rows'. Maybe instead of this you could use a listview?
Hi I have used ListFragment and simple ArrayAdapter quite often. And now I want to try some more by customizing BaseAdapter. But something happened, the List is not showing at all. I don't have any error (the Logcat also saying there're no error). But I debug it, and found out that getView() in my customized BaseAdapter is not called. I wonder why?
Here's the snippet:
#favorite_list_layout
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="@+id/favorite_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
#favorite_list_item
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/favorite_text"
android:layout_margin="5dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="0dp"
android:textSize="35sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/favorite_text_details"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:fontFamily="sans-serif-light"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
#FavoritesFragment
Code:
public class FavoritesFragment extends ListFragment {
[user=439709]@override[/user]
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//... setting variable favList, and this code is working. favList is not empty and there're no error
setListAdapter(new FavoriteAdapter(getActivity(), favList));
}
}
FavoriteAdapter, extends BaseAdapter
Code:
public class FavoriteAdapter extends BaseAdapter {
private Context ctx;
List<DMapData> list;
public FavoriteAdapter(Context context, List<DMapData> list) {
this.ctx = context;
this.list = list;
System.out.println("constructor executed!");
}
[user=439709]@override[/user]
public int getCount() {
return list.size();
}
[user=439709]@override[/user]
public Object getItem(int i) {
return list.get(i);
}
[user=439709]@override[/user]
public long getItemId(int i) {
return i;
}
[user=439709]@override[/user]
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println("GetView is executed"); //But it's not.
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.favorite_list_item, parent, false);
}
TextView favText = (TextView) rowView.findViewById(R.id.favorite_text);
TextView detailsText = (TextView) rowView.findViewById(R.id.favorite_text_details);
DMapData data = list.get(position);
System.out.println("DMapData from List");
favText.setText(data.getName());
detailsText.setText(data.getDetails().length()<=50? data.getDetails() : data.getDetails().substring(0, 51).concat("..."));
System.out.println("At the end of getView()");
return rowView;
}
}
Thanks
The id of the ListView has to be a special one so that the ListFragment can find it:
Code:
android:id="@android:id/list"
Hmm...
I have tried to change the id like your code. But, still not shown up. Is there anything I should do with my ListFragment?
nikwen said:
The id of the ListView has to be a special one so that the ListFragment can find it:
Code:
android:id="@android:id/list"
Click to expand...
Click to collapse
JoshieGeek said:
Hmm...
I have tried to change the id like your code. But, still not shown up. Is there anything I should do with my ListFragment?
Click to expand...
Click to collapse
Do you inflate your layout?
Code:
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_layout, container, false);
}
I always set the adapter in onCreate but there shouldn't be a difference.
Your layout looks like that now, right?
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
EDIT: Oh, add an orientation to the LinearLayout or replace it by a RelativeLayout.
And change the ListView heigth to match_parent.
Yupz. But still no different.
Here's my changed code. I have changed not using my customized adapter again, but instead using SimpleAdapter.
/res/layout/favorite_list_layout.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/res/layout/favorite_list_item
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/favorite_text"
android:layout_margin="5dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="0dp"
android:textSize="35sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/favorite_text_details"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:fontFamily="sans-serif-light"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/src/.../AllFragment.java
Code:
public class AllFragment extends ListFragment {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO get All Data
//Let's just adopt Favorite List Adapter for now
MasterDataReader mdReader = new MasterDataReader();
mdReader.execute();
List<DMapData> allList = new ArrayList<DMapData>();
allList.add(new DMapData("Empty", "No data found!"));
try {
allList = mdReader.get();
System.out.println("All List received");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
List<Map<String, String>> finList = new ArrayList<Map<String, String>>();
for(DMapData data : allList) {
Map<String, String> m = new HashMap<String, String>();
m.put("name", data.getName());
m.put("detail", data.getDetails().length()<=50? data.getDetails() : data.getDetails().substring(0, 51).concat("..."));
finList.add(m);
}
String[] colNames = new String[] {
"name", "detail"
};
int[] tView = new int[] {
R.id.favorite_text, R.id.favorite_text_details
};
SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), finList, R.layout.favorite_list_layout,
colNames, tView);
setListAdapter(simpleAdapter);
}
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.favorite_list_layout, container, false);
}
}
What do you think?
nikwen said:
Do you inflate your layout?
Code:
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_layout, container, false);
}
I always set the adapter in onCreate but there shouldn't be a difference.
Your layout looks like that now, right?
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
EDIT: Oh, add an orientation to the LinearLayout or replace it by a RelativeLayout.
And change the ListView heigth to match_parent.
Click to expand...
Click to collapse
JoshieGeek said:
Yupz. But still no different.
Here's my changed code. I have changed not using my customized adapter again, but instead using SimpleAdapter.
/res/layout/favorite_list_layout.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/res/layout/favorite_list_item
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/favorite_text"
android:layout_margin="5dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="0dp"
android:textSize="35sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/favorite_text_details"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:fontFamily="sans-serif-light"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
/src/.../AllFragment.java
Code:
public class AllFragment extends ListFragment {
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TODO get All Data
//Let's just adopt Favorite List Adapter for now
MasterDataReader mdReader = new MasterDataReader();
mdReader.execute();
List<DMapData> allList = new ArrayList<DMapData>();
allList.add(new DMapData("Empty", "No data found!"));
try {
allList = mdReader.get();
System.out.println("All List received");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
List<Map<String, String>> finList = new ArrayList<Map<String, String>>();
for(DMapData data : allList) {
Map<String, String> m = new HashMap<String, String>();
m.put("name", data.getName());
m.put("detail", data.getDetails().length()<=50? data.getDetails() : data.getDetails().substring(0, 51).concat("..."));
finList.add(m);
}
String[] colNames = new String[] {
"name", "detail"
};
int[] tView = new int[] {
R.id.favorite_text, R.id.favorite_text_details
};
SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), finList, R.layout.favorite_list_layout,
colNames, tView);
setListAdapter(simpleAdapter);
}
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.favorite_list_layout, container, false);
}
}
What do you think?
Click to expand...
Click to collapse
Try this layout:
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/list"
android:layout_alignParentTop="true"
android:fastScrollEnabled="true" />
<ProgressBar
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="?android:attr/progressBarStyle" />
</RelativeLayout>
It's working for me.
Did you try to write all entries to the logs? Do you get an output?
You know what? This is really make me laugh all the time, that it's because what I think is right but actually not. The list that I provided for my ListView is actually empty. Your layout tell me, because there's always the progressbar. Thank you very much for your help. :highfive:
nikwen said:
Try this layout:
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/list"
android:layout_alignParentTop="true"
android:fastScrollEnabled="true" />
<ProgressBar
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="?android:attr/progressBarStyle" />
</RelativeLayout>
It's working for me.
Did you try to write all entries to the logs? Do you get an output?
Click to expand...
Click to collapse
JoshieGeek said:
You know what? This is really make me laugh all the time, that it's because what I think is right but actually not. The list that I provided for my ListView is actually empty. Your layout tell me, because there's always the progressbar. Thank you very much for your help. :highfive:
Click to expand...
Click to collapse
Welcome.
I'm glad that you solved that because it began to drive me crazy. :laugh:
@JoshieGeek
consider using Log
Log.i("class/functionName","message you want to display");
Click to expand...
Click to collapse
It will be easy to debug
Sandeep_Jagtap said:
@JoshieGeek
consider using Log
It will be easy to debug
Click to expand...
Click to collapse
Didn't you see that he already solved his problem?
nikwen said:
Didn't you see that he already solved his problem?
Click to expand...
Click to collapse
Yes its quite noticeable
As he was saying he could not see error in Log while debugging. My advice to use log was for his future projects.
Sent from my Incredible S using xda app-developers app
Sandeep_Jagtap said:
Yes its quite noticeable
As he was saying he could not see error in Log while debugging. My advice to use log was for his future projects.
Sent from my Incredible S using xda app-developers app
Click to expand...
Click to collapse
OK.
Check out my guide on debugging here: http://forum.xda-developers.com/showthread.php?t=2325164
Hello ! I left my eclipse for a few days, after that my aplicaton for no reason is working bad. First Activity is opening as well, but aplication is closing when first activity is opening second. I was searching mistakes or errors in code but i have nothing. Below i paste code of first activity and second. Please help.
First Activity:
Code:
public class Pierwsza extends ActionBarActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pierwszy);
getSupportActionBar().hide();
Thread welcomeThread = new Thread()
{
@Override
public void run() {
try {
super.run();
sleep(3000) ; //Delay of 10 seconds
} catch (Exception e) {
} finally {
Intent i = new Intent(Pierwsza.this,
MainActivity.class);
startActivity(i);
finish();
}
}
};
welcomeThread.start();
}
}
second:
Code:
public class MainActivity extends ActionBarActivity {
ArrayAdapter<String> dataAdapter = null;
ArrayList<String> elementy = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
ListaPiosenek();
powiadomienie();
}
private void ListaPiosenek() {
ArrayList<String> elementy = new ArrayList<String>();
elementy.add("Dom w górach");
elementy.add("Jedyne co mam");
elementy.add("Koncert");
elementy.add("Ocean");
elementy.add("Tolerancja");
elementy.add("Wiesiek idzie");
elementy.add("Wiosna, ach to ty");
elementy.add("Chłopaki nie płaczą");
elementy.add("Dziki Włóczęga");
elementy.add("Imperatyw");
elementy.add("Piosenka Turystyczna III");
elementy.add("Remedium");
elementy.add("Kiedy będę starą kobietą");
elementy.add("Długość dźwięku samotności");
elementy.add("Król");
elementy.add("Anna");
elementy.add("Syn Miasta");
elementy.add("Samotna fregata");
elementy.add("Balonik");
elementy.add("Partyzant");
elementy.add("O mój rozmarynie");
elementy.add("Sosenka");;
// elementy.add("Długość dźwięku samotności");
// elementy.add("Długość dźwięku samotności");
// elementy.add("Długość dźwięku samotności");
// elementy.add("Długość dźwięku samotności");
// elementy.add("Długość dźwięku samotności");
Collections.sort(elementy);
final ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,R.layout.single_row,elementy);
final ListView list=(ListView)findViewById(R.id.listView1);
list.setAdapter(dataAdapter);
list.setFocusableInTouchMode(true);
list.requestFocus();
list.setTextFilterEnabled(true);
EditText myFilter =(EditText)findViewById(R.id.editText1);
myFilter.addTextChangedListener(new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
dataAdapter.getFilter().filter(s.toString());
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
}
private void powiadomienie() {
ListView list = (ListView)findViewById(R.id.listView1);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked,
int position, long id) {
String sText = ((TextView) viewClicked).getText().toString();
if(sText.equals("Dom w górach")){
Intent i = new Intent(MainActivity.this,Utwor0.class);
startActivity(i);
overridePendingTransition(R.animator.animation1, R.animator.animation2);
}
else if(sText.equals("Jedyne co mam")){
Intent i = new Intent(MainActivity.this, Utwor1.class);
startActivity(i);
}
else if(sText.equals("Koncert")){
Intent i = new Intent(MainActivity.this, Utwor2.class);
startActivity(i);
}
else if(sText.equals("Ocean")){
Intent i = new Intent(MainActivity.this, Utwor3.class);
startActivity(i);
}
else if(sText.equals("Tolerancja")){
Intent i = new Intent(MainActivity.this, Utwor4.class);
startActivity(i);
}
else if (sText.equals("Wiesiek idzie")){
Intent i = new Intent(MainActivity.this, Utwor5.class);
startActivity(i);
}
else if(sText.equals("Wiosna, ach to ty")){
Intent i = new Intent(MainActivity.this, Utwor6.class);
startActivity(i);
}
else if(sText.equals("Chłopaki nie płaczą")){
Intent i = new Intent(MainActivity.this, Utwor7.class);
startActivity(i);
}
else if(sText.equals("Dziki Włóczęga")){
Intent i = new Intent(MainActivity.this, Utwor8.class);
startActivity(i);
}
else if(sText.equals("Imperatyw")){
Intent i = new Intent(MainActivity.this, Utwor9.class);
startActivity(i);
}
else if(sText.equals("Piosenka Turystyczna III")){
Intent i = new Intent(MainActivity.this, Utwor10.class);
startActivity(i);
}
else if(sText.equals("Remedium")){
Intent i = new Intent(MainActivity.this, Utwor11.class);
startActivity(i);
}
else if(sText.equals("Kiedy będę starą kobietą")){
Intent i = new Intent(MainActivity.this, Utwor12.class);
startActivity(i);
}
else if(sText.equals("Długość dźwięku samotności")){
Intent i = new Intent(MainActivity.this, Utwor13.class);
startActivity(i);
}
else if(sText.equals("Król")){
Intent i = new Intent(MainActivity.this, Utwor14.class);
startActivity(i);
}
else if(sText.equals("Anna")){
Intent i = new Intent(MainActivity.this, Utwor15.class);
startActivity(i);
}
else if(sText.equals("Syn Miasta")){
Intent i = new Intent(MainActivity.this, Utwor16.class);
startActivity(i);
}
else if(sText.equals("Samotna fregata")){
Intent i = new Intent(MainActivity.this, Utwor17.class);
startActivity(i);
}
else if(sText.equals("Balonik")){
Intent i = new Intent(MainActivity.this, Utwor18.class);
startActivity(i);
}
else if(sText.equals("Partyzant")){
Intent i = new Intent(MainActivity.this, Utwor19.class);
startActivity(i);
}
else if(sText.equals("O mój rozmarynie")){
Intent i = new Intent(MainActivity.this, Utwor20.class);
startActivity(i);
}
else if(sText.equals("Sosenka")){
Intent i = new Intent(MainActivity.this, Utwor21.class);
startActivity(i);
}
}
});
}
}
Eclipse is not showing red errors in code.
Matma said:
Hello ! I left my eclipse for a few days, after that my aplicaton for no reason is working bad. First Activity is opening as well, but aplication is closing when first activity is opening second. I was searching mistakes or errors in code but i have nothing. Below i paste code of first activity and second. Please help.
First Activity:
Code:
public class Pierwsza extends ActionBarActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pierwszy);
getSupportActionBar().hide();
Thread welcomeThread = new Thread()
{
@Override
public void run() {
try {
super.run();
sleep(3000) ; //Delay of 10 seconds
} catch (Exception e) {
} finally {
Intent i = new Intent(Pierwsza.this,
MainActivity.class);
startActivity(i);
finish();
}
}
};
welcomeThread.start();
}
}
second:
Code:
public class MainActivity extends ActionBarActivity {
ArrayAdapter<String> dataAdapter = null;
ArrayList<String> elementy = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
ListaPiosenek();
powiadomienie();
}
private void ListaPiosenek() {
ArrayList<String> elementy = new ArrayList<String>();
elementy.add("Dom w górach");
elementy.add("Jedyne co mam");
elementy.add("Koncert");
elementy.add("Ocean");
elementy.add("Tolerancja");
elementy.add("Wiesiek idzie");
elementy.add("Wiosna, ach to ty");
elementy.add("Chłopaki nie płaczą");
elementy.add("Dziki Włóczęga");
elementy.add("Imperatyw");
elementy.add("Piosenka Turystyczna III");
elementy.add("Remedium");
elementy.add("Kiedy będę starą kobietą");
elementy.add("Długość dźwięku samotności");
elementy.add("Król");
elementy.add("Anna");
elementy.add("Syn Miasta");
elementy.add("Samotna fregata");
elementy.add("Balonik");
elementy.add("Partyzant");
elementy.add("O mój rozmarynie");
elementy.add("Sosenka");;
//elementy.add("Długość dźwięku samotności");
//elementy.add("Długość dźwięku samotności");
//elementy.add("Długość dźwięku samotności");
//elementy.add("Długość dźwięku samotności");
//elementy.add("Długość dźwięku samotności");
Collections.sort(elementy);
final ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,R.layout.single_row,elementy);
final ListView list=(ListView)findViewById(R.id.listView1);
list.setAdapter(dataAdapter);
list.setFocusableInTouchMode(true);
list.requestFocus();
list.setTextFilterEnabled(true);
EditText myFilter =(EditText)findViewById(R.id.editText1);
myFilter.addTextChangedListener(new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
dataAdapter.getFilter().filter(s.toString());
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
}
private void powiadomienie() {
ListView list = (ListView)findViewById(R.id.listView1);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked,
int position, long id) {
String sText = ((TextView) viewClicked).getText().toString();
if(sText.equals("Dom w górach")){
Intent i = new Intent(MainActivity.this,Utwor0.class);
startActivity(i);
overridePendingTransition(R.animator.animation1, R.animator.animation2);
}
else if(sText.equals("Jedyne co mam")){
Intent i = new Intent(MainActivity.this, Utwor1.class);
startActivity(i);
}
else if(sText.equals("Koncert")){
Intent i = new Intent(MainActivity.this, Utwor2.class);
startActivity(i);
}
else if(sText.equals("Ocean")){
Intent i = new Intent(MainActivity.this, Utwor3.class);
startActivity(i);
}
else if(sText.equals("Tolerancja")){
Intent i = new Intent(MainActivity.this, Utwor4.class);
startActivity(i);
}
else if (sText.equals("Wiesiek idzie")){
Intent i = new Intent(MainActivity.this, Utwor5.class);
startActivity(i);
}
else if(sText.equals("Wiosna, ach to ty")){
Intent i = new Intent(MainActivity.this, Utwor6.class);
startActivity(i);
}
else if(sText.equals("Chłopaki nie płaczą")){
Intent i = new Intent(MainActivity.this, Utwor7.class);
startActivity(i);
}
else if(sText.equals("Dziki Włóczęga")){
Intent i = new Intent(MainActivity.this, Utwor8.class);
startActivity(i);
}
else if(sText.equals("Imperatyw")){
Intent i = new Intent(MainActivity.this, Utwor9.class);
startActivity(i);
}
else if(sText.equals("Piosenka Turystyczna III")){
Intent i = new Intent(MainActivity.this, Utwor10.class);
startActivity(i);
}
else if(sText.equals("Remedium")){
Intent i = new Intent(MainActivity.this, Utwor11.class);
startActivity(i);
}
else if(sText.equals("Kiedy będę starą kobietą")){
Intent i = new Intent(MainActivity.this, Utwor12.class);
startActivity(i);
}
else if(sText.equals("Długość dźwięku samotności")){
Intent i = new Intent(MainActivity.this, Utwor13.class);
startActivity(i);
}
else if(sText.equals("Król")){
Intent i = new Intent(MainActivity.this, Utwor14.class);
startActivity(i);
}
else if(sText.equals("Anna")){
Intent i = new Intent(MainActivity.this, Utwor15.class);
startActivity(i);
}
else if(sText.equals("Syn Miasta")){
Intent i = new Intent(MainActivity.this, Utwor16.class);
startActivity(i);
}
else if(sText.equals("Samotna fregata")){
Intent i = new Intent(MainActivity.this, Utwor17.class);
startActivity(i);
}
else if(sText.equals("Balonik")){
Intent i = new Intent(MainActivity.this, Utwor18.class);
startActivity(i);
}
else if(sText.equals("Partyzant")){
Intent i = new Intent(MainActivity.this, Utwor19.class);
startActivity(i);
}
else if(sText.equals("O mój rozmarynie")){
Intent i = new Intent(MainActivity.this, Utwor20.class);
startActivity(i);
}
else if(sText.equals("Sosenka")){
Intent i = new Intent(MainActivity.this, Utwor21.class);
startActivity(i);
}
}
});
}
}
Eclipse is not showing red errors in code.
Click to expand...
Click to collapse
Is log showing something?
Gesendet von meinem LG-D855 mit Tapatalk
FATAL EXCEPTION: main
java.lang.OutOfMemoryError
E/AndroidRuntime(882): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/AndroidRuntime(882): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
E/AndroidRuntime(882): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
E/AndroidRuntime(882): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
E/AndroidRuntime(882): at android.content.res.Resources.loadDrawable(Resources.java:1965)
E/AndroidRuntime(882): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
E/AndroidRuntime(882): at android.view.View.<init>(View.java:3330)
E/AndroidRuntime(882): at android.widget.TextView.<init>(TextView.java:583)
E/AndroidRuntime(882): at android.widget.EditText.<init>(EditText.java:60)
E/AndroidRuntime(882): at android.support.v7.internal.widget.TintEditText.<init>(TintEditText.java:44)
E/AndroidRuntime(882): at android.support.v7.internal.widget.TintEditText.<init>(TintEditText.java:40)
E/AndroidRuntime(882): at android.support.v7.app.ActionBarActivityDelegateBase.createView(ActionBarActivityDelegateBase.java:759)
E/AndroidRuntime(882): at android.support.v7.app.ActionBarActivity.onCreateView(ActionBarActivity.java:552)
E/AndroidRuntime(882): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
E/AndroidRuntime(882): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
E/AndroidRuntime(882): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime(882): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime(882): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at com.example.another.MainActivity.onCreate(MainActivity.java:29)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
E/AndroidRuntime(882): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime(882): at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime(882): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime(882): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(882): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(882): at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime(882): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(882): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(882): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime(882): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime(882): at dalvik.system.NativeStart.main(Native Method)
Matma said:
FATAL EXCEPTION: main
java.lang.OutOfMemoryError
E/AndroidRuntime(882): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/AndroidRuntime(882): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
E/AndroidRuntime(882): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
E/AndroidRuntime(882): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
E/AndroidRuntime(882): at android.content.res.Resources.loadDrawable(Resources.java:1965)
E/AndroidRuntime(882): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
E/AndroidRuntime(882): at android.view.View.(View.java:3330)
E/AndroidRuntime(882): at android.widget.TextView.(TextView.java:583)
E/AndroidRuntime(882): at android.widget.EditText.(EditText.java:60)
E/AndroidRuntime(882): at android.support.v7.internal.widget.TintEditText.(TintEditText.java:44)
E/AndroidRuntime(882): at android.support.v7.internal.widget.TintEditText.(TintEditText.java:40)
E/AndroidRuntime(882): at android.support.v7.app.ActionBarActivityDelegateBase.createView(ActionBarActivityDelegateBase.java:759)
E/AndroidRuntime(882): at android.support.v7.app.ActionBarActivity.onCreateView(ActionBarActivity.java:552)
E/AndroidRuntime(882): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
E/AndroidRuntime(882): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
E/AndroidRuntime(882): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime(882): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime(882): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at com.example.another.MainActivity.onCreate(MainActivity.java:29)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
E/AndroidRuntime(882): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime(882): at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime(882): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime(882): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(882): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(882): at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime(882): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(882): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(882): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime(882): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime(882): at dalvik.system.NativeStart.main(Native Method)
Click to expand...
Click to collapse
It looks like there is an error in MainActivity line 29, could you please tell me which one that is so that we can better analyze it?
From looking at the stacktrace, there is probably an error concerning one of your layouts, as it says that "setContentView" has a problem. (I have marked those lines in the stacktrace in red)
--------------------
Phone: Nexus 4
OS: rooted Lollipop LRX21T
Bootloader: unlocked
Recovery: TWRP 2.8.2.0
29 line in Main Activity (second Activity in my first post) its
"private void ListaPiosenek()" and i dont know what i can change ;/
here is XML file (Activity Main layout)
Code:
<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.another.MainActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/horizontalScrollView1"
android:layout_below="@+id/editText1"
android:background="@drawable/tlo4"
android:descendantFocusability="beforeDescendants"
android:dividerHeight="2dp"
android:drawSelectorOnTop="true"
android:smoothScrollbar="true"
android:visibility="visible" >
</ListView>
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/listView1"
android:layout_alignParentBottom="true"
android:smoothScrollbar="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="79dp"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/a" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/a7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/am" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxWidth="70dp"
android:scaleType="centerInside"
android:src="@drawable/am7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/a6" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/amaj7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/asus" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/b" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/b6" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/b7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/bm" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/bm7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/bmaj7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/bsus" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/c" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/c7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/cm" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/cmaj7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/csus" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/d" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/d6" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/d7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/dm" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/dm7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/dmaj7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/e" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/e6" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/e7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/em" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/em7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/f" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/f6" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/f7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/fm" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/fmaj7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/fsus" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/g" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/g6" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/g7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/g9" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/gmaj7" />
</LinearLayout>
</HorizontalScrollView>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/imageView1"
android:layout_alignTop="@+id/imageView1"
android:layout_toRightOf="@+id/imageView1"
android:background="@drawable/szukajtlo"
android:ems="10"
android:hint="Szukaj" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/listView1"
android:layout_alignParentTop="true"
android:layout_marginBottom="20sp"
android:src="@drawable/logo144" />
</RelativeLayout>
I think your issue comes from too many / too big bitmaps loaded at the same time.
Before trying to use Bitmap.recycle() ar change bitmap configure, can you check that this is your issue removing some widgets witgh bitmaps?
Can you also test by removing hardware acceleration using this:
android:hardwareAccelerated="false"
Ecrou said:
I think your issue comes from too many / too big bitmaps loaded at the same time.
Before trying to use Bitmap.recycle() ar change bitmap configure, can you check that this is your issue removing some widgets witgh bitmaps?
Can you also test by removing hardware acceleration using this:
android:hardwareAccelerated="false"
Click to expand...
Click to collapse
I will try but tell me why its not working like this, cause it was, and i have working aplication on my phone :x ?
Oh i see now, you have a huge lot of image views inside your layout, this is too memory heavy. I would recommend using a listview where one item consists of a single imageview. Like that, there are always just a few images being loaded at once and the others are recycled. This is far more memory friendly
And i cant really imagine this could have ever worked nicely before, so i wonder how you could have run your app before..
--------------------
Phone: Nexus 4
OS: rooted Lollipop LRX21T
Bootloader: unlocked
Recovery: TWRP 2.8.2.0
Masrepus said:
Oh i see now, you have a huge lot of image views inside your layout, this is too memory heavy. I would recommend using a listview where one item consists of a single imageview. Like that, there are always just a few images being loaded at once and the others are recycled. This is far more memory friendly
And i cant really imagine this could have ever worked nicely before, so i wonder how you could have run your app before..
--------------------
Phone: Nexus 4
OS: rooted Lollipop LRX21T
Bootloader: unlocked
Recovery: TWRP 2.8.2.0
Click to expand...
Click to collapse
Its still working with that many imageViews on my phone, but i think i will delete it and make another Activty and Layout, thank you guys for help .
Matma said:
Its still working with that many imageViews on my phone, but i think i will delete it and make another Activty and Layout, thank you guys for help .
Click to expand...
Click to collapse
Yeah it depends on the device's ram and the heap settings if it crashes or not. But rather be safe than sorry
--------------------
Phone: Nexus 4
OS: rooted Lollipop LRX21T
Bootloader: unlocked
Recovery: TWRP 2.8.2.0