我将edittext放置在一个片段中,并且我还为该edittext添加了SetOnTouchListener,以便应用程序知道用户单击的字母的编号。问题是现在我无法再编辑edittext。我不知道为什么请帮助。 EditText位于片段内,仅在单击该方法时才会显示
public class MainFragment extends Fragment {
private Context context;
private ExpandableListView expandableListView;
public com.onedevz.noct.Adapters.ExpandableListAdapter expandableListAdapter;
private List<String> expandableListTitle;
public HashMap<String, List<String>> expandableListDetail;
private View view;
private LayoutInflater mInflater;
private ViewGroup mContainer;
public EditText editText;
public Button button;
HashMap<String, List<String>> expandableListDetailz = new HashMap<String, List<String>>();
List<String> title = new ArrayList<>();
public MainFragment(Context context) {
this.context = context;
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mInflater = inflater;
mContainer = container;
return showExpand();
}
@SuppressLint("ClickableViewAccessibility")
public View showNotes(){
mContainer.removeAllViews();
view = mInflater.inflate(R.layout.contentsingle,mContainer,false);
button = (Button)view.findViewById(R.id.returnButton);
editText = (EditText) view.findViewById(R.id.ContentText);
button.setText("< return");
editText.setText("");
editText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Layout layout = ((TextView) v).getLayout();
int x = (int)event.getX();
int y = (int)event.getY();
if (layout!=null){
int line = layout.getLineForVertical(y);
int offset = layout.getOffsetForHorizontal(line, x);
try{
char texts = editText.getText().charAt(offset);
Toast.makeText(context,"the offset are "+offset+"letter are "+texts,Toast.LENGTH_SHORT).show();
}catch (Exception e){
Toast.makeText(context,"the error are "+e,Toast.LENGTH_SHORT).show();
}
}
}
return true;
}
});
mContainer.addView(view);
return view;
}
public View showNote(){
mContainer.removeAllViews();
view = mInflater.inflate(R.layout.contentexpand,mContainer,false);
expandableListView = (ExpandableListView) view.findViewById(R.id.expandablelistview);
expandableListDetail = ExpandListData.getData();
expandableListTitle = new ArrayList<>( expandableListDetail.keySet() );
expandableListAdapter = new com.onedevz.noct.Adapters.ExpandableListAdapter( context,expandableListTitle,expandableListDetail );
expandableListView.setAdapter(expandableListAdapter);
expandableListAdapter.notifyDataSetChanged();
expandables();
mContainer.addView(view);
return view;
}
public View showNote2(){
mContainer.removeAllViews();
view = mInflater.inflate(R.layout.contentexpand,mContainer,false);
expandableListView = (ExpandableListView) view.findViewById(R.id.expandablelistview);
title.add( "Great" );
expandableListDetailz.put( "wow",title );
expandableListDetail = expandableListDetailz;
expandableListTitle = new ArrayList<>( expandableListDetail.keySet() );
expandableListAdapter = new com.onedevz.noct.Adapters.ExpandableListAdapter( context,expandableListTitle,expandableListDetail );
expandableListView.setAdapter(expandableListAdapter);
expandableListAdapter.notifyDataSetChanged();
expandables();
mContainer.addView(view);
return view;
}
public void showNote3(){
title.add( "new note" );
}
public View showCalendar(){
mContainer.removeAllViews();
view = mInflater.inflate(R.layout.contentdouble,mContainer,false);
expandableListView = (ExpandableListView) view.findViewById(R.id.ExpandableCalendarTask);
expandableListDetail = ExpandListData.getData();
expandableListTitle = new ArrayList<>( expandableListDetail.keySet() );
expandableListAdapter = new com.onedevz.noct.Adapters.ExpandableListAdapter( context,expandableListTitle,expandableListDetail );
expandableListView.setAdapter(expandableListAdapter);
expandableListAdapter.notifyDataSetChanged();
expandables();
mContainer.addView(view);
return view;
}
public View showSocial(){
mContainer.removeAllViews();
view = mInflater.inflate(R.layout.contentwebview,mContainer,false);
WebView webView = (WebView)view.findViewById( R.id.webview );
webView.setWebViewClient( new WebViewClient() );
webView.loadUrl( "http://www.facebook.com" );
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
mContainer.addView(view);
return view;
}
public View showExpand(){
view = mInflater.inflate(R.layout.contentexpand,mContainer,false);
expandableListView = (ExpandableListView) view.findViewById(R.id.expandablelistview);
expandableListDetail = ExpandListData.getData();
expandableListTitle = new ArrayList<>( expandableListDetail.keySet() );
expandableListAdapter = new com.onedevz.noct.Adapters.ExpandableListAdapter( context,expandableListTitle,expandableListDetail );
expandableListView.setAdapter(expandableListAdapter);
expandableListAdapter.notifyDataSetChanged();
expandables();
return view;
}
public void expandables(){
expandableListView.setOnGroupClickListener( new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
Log.v( "expand","i am clicked"+groupPosition );
return false;
}
} );
expandableListView.setOnChildClickListener( new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
String country = (String)expandableListAdapter.getChild(groupPosition, childPosition);
Log.v( "i am at group"+groupPosition,"row at "+country );
Toast.makeText( context,"i am at"+childPosition,Toast.LENGTH_SHORT ).show();
return true;
}
} );
}
}
答案 0 :(得分:0)
来自:官方文档View.OnTouchListener
onTouch 返回:布尔值
如果侦听器已经使用了事件,则为真,否则为false。
答案 1 :(得分:0)
尝试一下,
sip.so
});