2011-10-29 4 views
0

アンドロイドについて学習することを目的として、JavaビデオレッスンでDeveloping Androidアプリケーションを購入しました。チュートリアルでは、隣に「チェックボックス」を付けてタスクを追加する方法を学習します私はタスクを評価するために、タスクの下に評価バーを追加する方法を知りたいと思います。私は別のものを試しましたが、何も働かなかったのです。コード全体を貼り付けるほどです関連する部品を特定しようとしますAndroidチェックボックスと評価付きのタスクを追加

プロジェクトには3つのグラフィカルレイアウト(xmlファイル)があります。タスクのリストを提示するための最初のもの、必要なボタン(タスクの追加、削除)を持つ第2のもの、チェックボックスをオンにして、うまくいけば評価バーも。私たちは、チェックボックスと対話する必要があるため、この評価のバーを行うことにより

<?xml version="1.0" encoding="utf-8"?> 
    <project.android.taskmanager.views.TaskListItem 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <CheckedTextView 
    android:id="@android:id/text1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
    android:gravity="center_vertical" 
    android:checkMark="?android:attr/listChoiceIndicatorMultiple" /> 

は、グラフィカルなレイアウト上のXMLファイルに使用されるクラス以下

<RatingBar android:id="@+id/ratingbar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@android:id/text1" 
    android:numStars="5" 
    android:isIndicator="true" 
    android:stepSize="0.1"/> 
</project.android.taskmanager.views.TaskListItem> 

に表示されます。

 package project.android.taskmanager.views; 
     import project.android.taskmanager.R; 
     import project.android.taskmanager.tasks.Task; 

     import android.content.Context; 
     import android.util.AttributeSet; 
     import android.widget.CheckedTextView; 
     import android.widget.LinearLayout; 
     import android.widget.RatingBar; 
     import android.widget.RatingBar.OnRatingBarChangeListener; 
     import android.widget.RelativeLayout; 


    public class TaskListItem extends RelativeLayout { 

    private Task task; 
    private CheckedTextView checkbox; 
    private RatingBar ratingbar; 




    public TaskListItem(Context context, AttributeSet attrs) { 
     super(context, attrs); 

    } 

    @Override 
    protected void onFinishInflate() { 
     super.onFinishInflate(); 
     checkbox = (CheckedTextView)findViewById(android.R.id.text1); 
     ratingbar = (RatingBar)findViewById(R.id.ratingbar); 


    } 

    public void setTask(Task task) { 
     this.task = task; 
     checkbox.setText(task.getName()); 

     checkbox.setChecked(task.isComplete()); 

    } 

    public Task getTask() { 
     return task; 
    } 

} 

以下を追加しても機能しませんでした。

final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar); 
ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { 
    public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { 
     Toast.makeText(HelloFormStuff.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show(); 
    } 
}); 

ユーザーが対話できるように、チェックボックスの横に評価バーを追加するにはどうすればよいですか?

+0

あなたの* TaskListItem *はXMLリソースから膨らんでいますか?そのXMLはどのように見えますか? – JimmyB

+0

TaskListItemクラスは上記のxmlとのみ相関関係にあるため、ウィジェットを対話可能にすることができます。 – Stefan

答えて

0

全体の設定方法はわかりませんが、RelativeLayoutの中にすべてを入れて、チェックボックスに値android:layout_alignParentRight="true" android:layout_alignParentBottom="true"android:id="@+id/checkbox"を割り当ててください。 次に、評価バーに値android:layout_alignParentBottom="true"android:layout_toLeftOf="@+id/checkbox"を割り当てます。

これが設定する方法がうまくいくのかどうかわかりませんが、私があなたが達成しようとしていることを理解しているので、これをやる方法です。

関連する問題