-1

如何在 Eclipse 中创建点击事件搜索按钮?有人能帮我吗。这是我正在使用的代码。

protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_search);

      listContent1 = (ListView)findViewById(R.id.lFoodlist1);

      mySQLiteAdapter = new SQLiteAdapter(this);
      mySQLiteAdapter.openToRead();

      Cursor cursor = mySQLiteAdapter.queueAll();

      startManagingCursor(cursor);

      String[] from = new String[]{SQLiteAdapter.KEY_FOODNAME,SQLiteAdapter.KEY_CALORIES};
      int[] to = new int[]{R.id.tv1, R.id.tv2};

      SimpleCursorAdapter cursorAdapter =
      new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);

      listContent1.setAdapter(cursorAdapter);
      //listContent.setOnItemClickListener(listContentOnItemClickListener);*/

  }
4

1 回答 1

0

这段代码取自这里并被修改/评论以帮助他的场景。

您可以实现swing以帮助您的应用程序的 GUI 方面。其他人可能更喜欢AWT

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class myTest {

    public static void main(String[] args) {

        //This will create the JFrame/JPanel/JButton
        final JFrame frame = new JFrame();
        JPanel panel = new JPanel();
        JButton button1 = new JButton();

        //Add your panel and button and make them visable
        frame.add(panel);
        panel.add(button1);
        frame.setVisible(true);

        //This adds the actionListener to the Button
        button1.addActionListener(new ActionListener() {

            //When the button is clicked this action will be performed
            public void actionPerformed(ActionEvent arg0) {
                //Add your code here.
            }
        });

    }

}
于 2013-01-31T16:38:47.257 回答