gpt4 book ai didi

java - Eclipse Android 两个按钮

转载 作者:行者123 更新时间:2023-12-02 06:36:08 25 4
gpt4 key购买 nike

请帮助我!我想制作一个公交车时刻表应用程序,但我无法使用两个按钮来完成此 Activity 。它说“在类型 _tiz_oda 中复制方法 addListenerOnButton()”。 Activity 布局:

<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="._tiz_oda" >

<TextView
android:id="@+id/textView_10_oda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/text_10_1"
android:textSize="18sp" />

<TextView
android:id="@+id/textView_10_10_oda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/button_10"
android:textSize="18sp" />

<TextView
android:id="@+id/textView_10_ora_oda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/button_10_oda"
android:text="@string/text_ora" />

<TextView
android:id="@+id/textView_10_ures_oda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView_10_munkanap_oda"
android:layout_below="@+id/textView_10_munkanap_oda"
android:layout_marginTop="24dp"
android:text="@string/text_ures" />

<TextView
android:id="@+id/textView_10_szabad_oda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_10_oda"
android:layout_toRightOf="@+id/textView_10_munkanap_oda"
android:text="@string/text_szabad" />

<GridView
android:id="@+id/gridView_10_oda"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView_10_szabad_oda"
android:layout_centerHorizontal="true"
android:numColumns="3" />

<Button
android:id="@+id/button_10_megallok_oda"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/button_10_oda"
android:text="@string/text_megallok" />

<Button
android:id="@+id/button_10_oda"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView_10_irany_oda"
android:text="@string/text_10_3" />

<TextView
android:id="@+id/textView_10_irany_oda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button_10_oda"
android:layout_below="@+id/textView_10_oda"
android:layout_marginLeft="33dp"
android:text="@string/text_irany" />

<TextView
android:id="@+id/textView_10_munkanap_oda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView_10_ora_oda"
android:layout_alignBottom="@+id/textView_10_ora_oda"
android:layout_alignLeft="@+id/textView_10_oda"
android:layout_marginLeft="20dp"
android:text="@string/text_munkanap" />

</RelativeLayout>

和 Activity .java:

package com.szfvar.buszmenetrend;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;

public class _tiz_oda extends Activity {

Button button;

GridView gridView_10;

static final String[] numbers = new String[] {
"4", "35,50", "35",
"5", "00,20,50", "20",
"6", "25,50", "25",
"7", "20", "20",
"8", "20", "20",
"9", "20", "20",
"10", "20", "20",
"11", "20", "20",
"12", "20,45", "20",
"13", "20,50", "20",
"14", "20,50", "25",
"15", "20,50", "20",
"16", "20,50", "20",
"17", "20,50", "20",
"18", "20", "20",
"19", "00,25", "25",
"20", "25", "25",
"21", "20", "20",
"22", "35", "35",};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_tiz_oda);

gridView_10 = (GridView) findViewById(R.id.gridView_10_oda);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, numbers);

gridView_10.setAdapter(adapter);

gridView_10.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(getApplicationContext(),
((TextView) v).getText(), Toast.LENGTH_SHORT).show();
}
});
addListenerOnButton();
}

public void addListenerOnButton() {

final Context context = this;

button = (Button) findViewById(R.id.button_10_oda);

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

Intent intent = new Intent(context, _tiz_vissza.class);
startActivity(intent);

}

});
addListenerOnButton();
}

public void addListenerOnButton() {

final Context context = this;

button = (Button) findViewById(R.id.button_10_megallok_oda);

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

Intent intent = new Intent(context, _tiz_megallok_oda.class);
startActivity(intent);

}

});


}

}

请帮忙!提前致谢!

最佳答案

您已声明此方法,public void addListenerOnButton() {两次。

你不能这么做。否则,当你调用它时,编译器如何知道使用哪一个?

相反:

public void addListenerOnButton() {

final Context context = this;

button = (Button) findViewById(R.id.button_10_oda);

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

Intent intent = new Intent(context, _tiz_vissza.class);
startActivity(intent);

}

otherButton = (Button) findViewById(R.id.button_10_megallok_oda);

otherButton .setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

Intent intent = new Intent(context, _tiz_megallok_oda.class);
startActivity(intent);

}
});

}

当然,您应该使用比 button 更好的名称和otherButton喜欢 10_oda10_megallok_oda .

关于java - Eclipse Android 两个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19623487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com