Android用のコーディングでは本当に新しいので、ちょうど学び始めました。私は、テキストボックスに表示される値を変更するいくつかの画像ボタンを持っており、私はこれを行う方法を知らない。私はボタンのいくつかのテストを試みたが、私は修復できないいくつかのエラーがある。食からAndroidボタンのクリックがうまくいかず、テキストボックスを編集しています
メッセージ:
型ビューの方法setOnClickListener(View.OnClickListener)は引数に適用されない(新しいOnClickListener(){})
と
方法(新しいOnClickListener(){})
setOnClickListenerとOnClickListenerのsetOnClickListener(View.OnClickListener)は、引数には適用されません
私は、このスレッドを見て、それでも私はそれを除いて
を何をするか分からない、私はボタン付きミディアムテキストフィールドを変更したいです。おそらく宣言された整数によって。
コード:
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
Button b1;
Button b2;
Button b3;
Button b4;
Button b5;
Button b6;
Button b7;
Button b8;
int vs,vh,ws,wh,wth,wts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button) findViewById(R.id.imageButton1);
b1.setOnClickListener(new OnClickListener()
{
protected void onClick(View v)
{
Toast.makeText(ApplicationContext(), "Om nom nom", Toast.LENGTH_SHORT).show();
}
});
}
XML
<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:background="#012e53"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
tools:context="pl.tmalachowski.truewindcalc.MainActivity" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="26dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:orientation="vertical"
android:textColor="#bdc3c7" >
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/ves"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/podst" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center" >
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/rel"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/podst" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center" >
<TextView
android:id="@+id/textView1"
android:layout_width="62dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/ves1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/podst" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center" >
<TextView
android:id="@+id/textView2"
android:layout_width="77dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/ves2"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/podst" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center" >
<TextView
android:id="@+id/textView3"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/rel1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/podst" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center" >
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/rel2"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/podst" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/arrow_up_float" />
</LinearLayout>
はsetOnClickListener(新しいOnClickListener() – Masum