我正在使用a searchView并尝试在有人调用搜索时传递一些数据.所以我覆盖了这个onSearchReqested方法.问题是,当有人输入SearchView并按下键盘上的放大镜时,不会调用此方法.而是启动结果活动.
onSearchRequested当有人按下放大镜时,如何在开始结果活动之前调用该方法.
我尝试了这两个但它没有用.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.FLAG_EDITOR_ACTION) {
onSearchRequested();
return false;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
向searchview添加一个监听器也不起作用
searchView.setOnSearchClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onSearchRequested();
}
});
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助.
我遇到了以下问题.我有一个listview和两个按钮.在片段的开头,一些数据存储在2个Arraylists中.首先,第一个Arraylist的内容显示在listview中,工作正常.当用户单击第一个按钮时,ListView会显示第二个ArrayList.这对用户来说很好,但只要我调用adapter.clear().第一个Arraylist被删除了.因此,他无法通过单击第一个按钮切换回第一个列表.我从不删除Arraylist,所以我想知道为什么adapter.clear()会这样做.你能帮忙的话,我会很高兴.代码在下面.
public class MessagesFragment extends Fragment {
private ArrayList<Message> outbound;
private ArrayList<Message> inbound;
private MessageAdapter messageadapter;
private int box;
private View rootView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_messages, container,
false);
outbound = new ArrayList<Message>();
inbound = new ArrayList<Message>();
this.rootView = rootView;
box = 0;
messageadapter = new MessageAdapter(getActivity(),
R.layout.item_message, inbound);
((ListView) rootView.findViewById(R.id.lv_message))
.setAdapter(messageadapter);
initializeListeners();
return rootView;
}
private void initializeListeners() {
rootView.findViewById(R.id.rb_message_inbox).setOnClickListener(
new OnClickListener() {
@Override
public void onClick(View v) {
showBox(0); …Run Code Online (Sandbox Code Playgroud) 我有一个JPanel,上面画了一个三角形.当有人点击按钮时,应使用新参数重新绘制三角形.问题是旧的三角形仍然存在,新的三角形与下面的文本字段的一部分混乱.
public class Vermessung {
private static void eingabe(){
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(screen.height/2, screen.height/4*3);
JPanel jp = new JPanel();
jp.setLayout(new BoxLayout(jp, BoxLayout.PAGE_AXIS));
//Eingabebereich
JPanel eingabebereich = new JPanel(new GridLayout(3, 1));
JPanel abc = new JPanel(new GridLayout(4, 2));
abc.add(new JLabel("Strecke"));
abc.add(new JLabel("Gemessener Wert in [m]"));
abc.add(new JLabel("a:"));
abc.add(tfa);
abc.add(new JLabel("b:"));
abc.add(tfb);
abc.add(new JLabel("c:"));
abc.add(tfc);
//AusgabeBereich
JPanel ausgabe = new JPanel(new GridLayout(2, 3));
ausgabe.add(new JLabel("p [m]"));
ausgabe.add(new JLabel("q [m]"));
ausgabe.add(new JLabel("h [m]"));
ausgabe.add(P);
ausgabe.add(Q);
ausgabe.add(H);
P.setEditable(false);
Q.setEditable(false);
H.setEditable(false);
//Buttons mit Listenern
JPanel buttons = …Run Code Online (Sandbox Code Playgroud) 我创建了一个扩展类Asynctask.从多个活动中调用此类.它从网页获取一些数据.之后,根据url,数据将在onPostExecute方法中处理.现在我使用多个else if语句,但它有点不方便.
有没有办法onPostExecute在创建新的Activity的Activity中定义方法Asynctask.
我认为它可能适用于接口或抽象方法,但我不确定,也不知道如何.