Visualizzazione stampabile
-
salve ,
studiando e smanettando un pò con il codice per sviluppare con android ho notato che alcuni esempi trovati sul libro "Professional Android Application Development" in particolare gli esempi todoList e Customizing Your To-Do List l'emulatore da in output un errore in particolare scrive che l'applicazione è stata terminata inprovvisamente sapete aiutarmi a far capire il problema
il processo terminato è process com.paad.todolist
-
Quote:
Originariamente inviato da
luca
salve ,
studiando e smanettando un pò con il codice per sviluppare con android ho notato che alcuni esempi trovati sul libro "Professional Android Application Development" in particolare gli esempi todoList e Customizing Your To-Do List l'emulatore da in output un errore in particolare scrive che l'applicazione è stata terminata inprovvisamente sapete aiutarmi a far capire il problema
il processo terminato è process com.paad.todolist
Luca servono più info per aiutarti posta l'esempio e vediamo
-
Quote:
Originariamente inviato da
Rixxo
Luca servono più info per aiutarti posta l'esempio e vediamo
di seguito riporto il codice di todolist.java
package com.paad.todolist;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
public class TodoList extends Activity {
/** Called when the activity is first created. */
@Override
/*
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
public void onCreate(Bundle icicle) {
// Inflate your view
setContentView(R.layout.main);
// Get references to UI widgets
ListView myListView = (ListView)findViewById(R.id.myListView);
final EditText myEditText = (EditText)findViewById(R.id.myEditText);
}
*/
public void onCreate(Bundle icicle) {
setContentView(R.layout.main);
ListView myListView = (ListView)findViewById(R.id.myListView);
final EditText myEditText = (EditText)findViewById(R.id.myEditText);
final ArrayList<String> todoItems = new ArrayList<String>();
int resID = R.layout.todolist_item;
final ArrayAdapter<String> aa = new ArrayAdapter<String>(this, resID, todoItems);
myListView.setAdapter(aa);
myEditText.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN)
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
{
todoItems.add(0, myEditText.getText().toString());
aa.notifyDataSetChanged();
myEditText.setText("ppppp");
return true;
}
return false;
}
});
}
}
successivamente il libro presenta una modifica al progetto in più passi:
Create a new TodoListItemView class that extends TextView. Include a stub for overriding the
onDraw method, and implement constructors that call a new init method stub.
package com.paad.todolist;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;
public class TodoListItemView extends TextView {
public TodoListItemView (Context context, AttributeSet ats, int ds) {
super(context, ats, ds);
init();
}
public TodoListItemView (Context context) {
super(context);
init();
}
public TodoListItemView (Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
}
@Override
public void onDraw(Canvas canvas) {
// Use the base TextView to render the text.
super.onDraw(canvas);
}
}
84
Chapter 4: Creating User Interfaces
2. Create a new colors.xml resource in the res/values folder. Create new color values for the
paper, margin, line, and text colors.
<?xml version=”1.0” encoding=”utf-8”?>
<resources>
<color name=”notepad_paper”>#AAFFFF99</color>
<color name=”notepad_lines”>#FF0000FF</color>
<color name=”notepad_margin”>#90FF0000</color>
<color name=”notepad_text”>#AA0000FF</color>
</resources>
3. Create a new dimens.xml resource fi le, and add a new value for the paper’s margin width.
<?xml version=”1.0” encoding=”utf-8”?>
<resources>
<dimen name=”notepad_margin”>30px</dimen>
</resources>
4. With the resources defi ned, you’re ready to customize the TodoListItemView appearance.
Create new private instance variables to store the Paint objects you’ll use to draw the paper
background and margin. Also create variables for the paper color and margin width values.
Fill in the init method to get instances of the resources you created in the last two steps and
create the Paint objects.
private Paint marginPaint;
private Paint linePaint;
private int paperColor;
private float margin;
private void init() {
// Get a reference to our resource table.
Resources myResources = getResources();
// Create the paint brushes we will use in the onDraw method.
marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
marginPaint.setColor(myResources.getColor(R.color. notepad_margin));
linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
linePaint.setColor(myResources.getColor(R.color.no tepad_lines));
// Get the paper background color and the margin width.
paperColor = myResources.getColor(R.color.notepad_paper);
margin = myResources.getDimension(R.dimen.notepad_margin);
}
5. To draw the paper, override onDraw, and draw the image using the Paint objects you created
in Step 4. Once you’ve drawn the paper image, call the superclass’s onDraw method, and let it
draw the text as usual.
@Override
public void onDraw(Canvas canvas) {
// Color as paper
canvas.drawColor(paperColor);
// Draw ruled lines
85
Chapter 4: Creating User Interfaces
canvas.drawLine(0, 0, getMeasuredHeight(), 0, linePaint);
canvas.drawLine(0, getMeasuredHeight(),
getMeasuredWidth(), getMeasuredHeight(),
linePaint);
// Draw margin
canvas.drawLine(margin, 0, margin, getMeasuredHeight(), marginPaint);
// Move the text across from the margin
canvas.save();
canvas.translate(margin, 0);
// Use the TextView to render the text.
super.onDraw(canvas);
canvas.restore();
}
6. That completes the TodoListItemView implementation. To use it in the To-Do List Activity,
you need to include it in a new layout and pass that in to the Array Adapter constructor.
Start by creating a new todolist_item.xml resource in the res/layout folder. It will specify how
each of the to-do list items is displayed. For this example, your layout need only consist of the
new TodoListItemView, set to fi ll the entire available area.
<?xml version=”1.0” encoding=”utf-8”?>
<com.paad.todolist.TodoListItemView
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:padding=”10dp”
android:scrollbars=”vertical”
android:textColor=”@color/notepad_text”
android:fadingEdge=”vertical”
/>
7. Now open the ToDoList Activity class. The fi nal step is to change the parameters passed in
to the ArrayAdapter in onCreate. Replace the reference to the default android.R.layout
.simple_list_item_1 with the new R.layout.todolist_item layout created in Step 6.
final ArrayList<String> todoItems = new ArrayList<String>();
int resID = R.layout.todolist_item;
final ArrayAdapter<String> aa = new ArrayAdapter<String>(this, resID, todoItems);
myListView.setAdapter(aa);
-
posta anche il:
- main.xml
- AndroidManifest.xml
Comunque nella classe TodoList nella funzione onCreate manca super.onCreate(icicle);
-
Quote:
Originariamente inviato da
Rixxo
posta anche il:
- main.xml
- AndroidManifest.xml
Comunque nella classe TodoList nella funzione onCreate manca super.onCreate(icicle);
questo è il main.xml
<?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”>
<EditText
android:id=”@+id/myEditText”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”New To Do Item”
/>
<ListView>
android:id=”@+id/myListView”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
/>
</LinearLayout>
mentre questo è l'AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.paad.todolist"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TodoList"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
-
Infatti è come ti dicevo l'ho provato personalmente e manca nella funzione onCreate super.onCreate(icicle);
Questa è la funzione onCreate() che devi scrivere:
codice:
public class ToDoList extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle); //Andava soltanto inserito questo
setContentView(R.layout.main);
ListView myListView = (ListView)findViewById(R.id.myListView);
final EditText myEditText = (EditText)findViewById(R.id.myEditText);
final ArrayList<String> todoItems = new ArrayList<String>();
int resID = R.layout.todolist_item;
final ArrayAdapter<String> aa = new ArrayAdapter<String>(this, resID, todoItems);
myListView.setAdapter(aa);
myEditText.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN)
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
{
todoItems.add(0, myEditText.getText().toString());
aa.notifyDataSetChanged();
myEditText.setText("ppppp");
return true;
}
return false;
}
});
}
}
poi nel main.xml apporta le seguenti correzioni:
codice:
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
androidrientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<EditText
android:id=”@+id/myEditText”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”New To Do Item”
/>
<ListView> /* non va scritto cosi ma nel seguente modo */
<ListView
android:id=”@+id/myListView”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
/>
</LinearLayout>
Prova tutto e fammi sapere come va? ;)
-
grazie per l'aiuto.....ma penso sia un limite dell'emulatore o un bag perchè anche apportando le correzioni sopra indicate cmq viene lanciato un messaggio di errore.Il msg è il seguente:
SORRY
The application TodoList
(processed com.paad.todolist)
has stopped unexpectedly.
please try again.
-
Con quale sdk stai sviluppando 1.1 o 1.5?
Io sta usansndo la nuova versione dell'1.5 la r2.
Poi mi fai un favore mi dice se all'interno del tab Problems di eclipse vedi errori?
-
Quote:
Originariamente inviato da
Rixxo
Con quale sdk stai sviluppando 1.1 o 1.5?
Io sta usansndo la nuova versione dell'1.5 la r2.
Poi mi fai un favore mi dice se all'interno del tab Problems di eclipse vedi errori?
si anche io stò utilizzando la 1.5
problems in eclipse dice
Description Resource Path Location Type
The import android.content.res.Resources is never used TodoListItemView.java TodoList1/src/com/paad/todolist line 3 Java Problem
The import android.graphics.Paint is never used TodoListItemView.java TodoList1/src/com/paad/todolist line 5 Java Problem
-
Salve
Ho scaricato la sdk 1.5 r2 per Windows, ma in Eclipse (Eclipse Ganymede 3.4.2) non riesco ad installare il plugin ADT.
Ho seguito la guida, ma dopo aver scaricato i plugins, ottengo una fila lunghissima di errori durante l'installazione :( :
Cannot complete the request. See the details.
Unsatisfied dependency: [com.android.ide.eclipse.adt.feature.group 0.9.1.v200905011822-1621] requiredCapability: org.eclipse.equinox.p2.iu/org.eclipse.wst.sse.core/0.0.0
Unsatisfied dependency: [com.android.ide.eclipse.adt.feature.group 0.9.1.v200905011822-1621] requiredCapability: org.eclipse.equinox.p2.iu/org.eclipse.wst.xml.core/0.0.0
Unsatisfied dependency: [com.android.ide.eclipse.adt.feature.group 0.9.1.v200905011822-1621] requiredCapability: org.eclipse.equinox.p2.iu/org.eclipse.wst.xml.ui/0.0.0
Unsatisfied dependency: [com.android.ide.eclipse.adt.feature.group 0.9.1.v200905011822-1621] requiredCapability: org.eclipse.equinox.p2.iu/org.eclipse.wst.sse.ui/0.0.0
Unsatisfied dependency: [com.android.ide.eclipse.adt.feature.group 0.9.1.v200905011822-1621] requiredCapability: org.eclipse.equinox.p2.iu/org.eclipse.gef/0.0.0
Unsatisfied dependency: [com.android.ide.eclipse.adt.feature.group 0.9.1.v200905011822-1621] requiredCapability: org.eclipse.equinox.p2.iu/org.eclipse.wst.sse.ui/0.0.0
Unsatisfied dependency: [com.android.ide.eclipse.adt.feature.group 0.9.1.v200905011822-1621] requiredCapability: org.eclipse.equinox.p2.iu/org.eclipse.gef/0.0.0
Unsatisfied dependency: [com.android.ide.eclipse.adt.feature.group 0.9.1.v200905011822-1621] requiredCapability: org.eclipse.equinox.p2.iu/org.eclipse.wst.xml.ui/0.0.0
Unsatisfied dependency: [com.android.ide.eclipse.adt.feature.group 0.9.1.v200905011822-1621] requiredCapability: org.eclipse.equinox.p2.iu/org.eclipse.wst.sse.core/0.0.0
Unsatisfied dependency: [com.android.ide.eclipse.adt.feature.group 0.9.1.v200905011822-1621] requiredCapability: org.eclipse.equinox.p2.iu/org.eclipse.wst.xml.core/0.0.0
Qualcuno saprebbe aiutarmi ?
Grazie..