[Q] ArrayAdapter and custom layout - Android Software Development

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?

Related

Compound Controls

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

[Q] unable to switch activity

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>

[Q] ListView with BaseAdapter not showing

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

[Q] setText don't change text

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.....

[Q]Dealing with fragments

Here is the xml
Code:
<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"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="40.0dip"
android:background="#ffffffff"
android:id="@+id/progaction"
android:layout_weight="0.2"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_below="@id/container"
android:layout_alignParentBottom="true">
<TextView
android:gravity="center"
android:text="Level"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
/>
<SeekBar
android:gravity="center"
android:layout_weight="1"
android:id="@+id/seek"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/><TextView
android:gravity="center"
android:text="1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/prog"
/>
</LinearLayout>
</LinearLayout>
Framelayout with id=container contains the fragment used in the activity.
Now the problem is that how to can i get the value of the textView(id=prog) in a particular fragment.i am not able to do it
Error says that "this method cant be used for static context" for the following line
Code:
TextView prog=(TextView) findViewById(R.id.prog);
So please help me to get the value of textView in a fragment
Sent from my GT-S5570 using XDA Premium 4 mobile app
I think your need to call getActivity() first and after this perform activity.findViewById(R.id.prog):
HTML:
Activity a = getActivity();
TextView prog=(TextView) a.findViewById(R.id.prog);
well maybe the easiest way is to hold an instance of the textView in the fragment code, then have a public method to return that instance, so that in the main fragment activity you simply get an instance to the fragment then call the method ?
Have you tried this one? http://stackoverflow.com/questions/6495898/findviewbyid-in-fragment-android
danelab said:
I think your need to call getActivity() first and after this perform activity.findViewById(R.id.prog):
HTML:
Activity a = getActivity();
TextView prog=(TextView) a.findViewById(R.id.prog);
Click to expand...
Click to collapse
Thanks.it worked
nikwen said:
Have you tried this one? http://stackoverflow.com/questions/6495898/findviewbyid-in-fragment-android
Click to expand...
Click to collapse
This is to be used if textView is present in the XML inflated by the fragment itself .but my textView is in XML of mainactivity.
Anyways thanks for the answer.I got the solution
Sent from my GT-S5570 using XDA Premium 4 mobile app

Categories

Resources