我不会有什么问题。没有任何错误,程序运行完美。但是,当我单击列表视图中的一个项目时,它不会执行任何操作。换句话说,“吐司”不会通过
这是我的主要课程:
public class ViewListAct extends ActionBarActivity {
private ListView list;
private final String[] names_1 = {"McDonald's", "Subway", "Pizza Hut", "Burger King"};
private final String[] img_1 = {"mcd", "mcd", "mcd", "mcd"};
private Activity context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_list);
list = (ListView) findViewById(R.id.listview);
AdapterView adapter = new AdapterView(this, img_1, names_1);
list.setAdapter(adapter);
list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
@Override
public void onItemClick(android.widget.AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(), names_1[position], Toast.LENGTH_LONG).show();
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是我的自定义适配器类:
public class AdapterView extends …Run Code Online (Sandbox Code Playgroud) 我是 Java 新手,正在开发一个使用 GUI 的程序。我的问题是我已经达到了1000 行,这很有压力,因为我所有的代码都在一个文件中。我不喜欢这个。所以我在互联网上研究了继承。但是,我不确定这如何帮助我解决我的问题,因为我所知道的所有继承都继承了父类中的所有内容。但是,当我尝试在子类中使用变量时,我不能说我在父类中有这样的东西:
JButton getButton = new JButton("Enter");
现在当我去儿童班时。我想继承并使用这个变量,所以我可以使用它不工作的 ActionListener。
那么有人可以告诉我我在这里做错了什么,或者这不是正确的方法吗?
前后谢谢大家。
这是我的一些代码:
public class H_Store extends JFrame {
private JCheckBox groundMeatCheckBox;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
H_Store frame = new H_Store();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public H_Store() {
super("Hussin Store");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1378, 657); …Run Code Online (Sandbox Code Playgroud)