我想使用ButterKnife绑定我在listView adpater中的视图.
我试过这个,但我不能简单地使用我的"旋转器"var.
public class WarmSpinnerAdapter extends ArrayAdapter<Warm> {
Context context;
public WarmSpinnerAdapter(Context context, int resource, Warm[] objects) {
super(context, resource, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = LayoutInflater.from(context).inflate(R.layout.item_spinner, null);
return v;
}
@OnClick(R.id.spinner)
public void onClick() {
//open dialog and select
}
static class ViewHolder {
@BindView(R.id.spinner)
MyTextView spinner;
ViewHolder(View view) {
ButterKnife.bind(this, view);
}
}
}
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
我在应用程序中有一些登录页面.但是,当我专注于TextFormField时,键盘覆盖字段并且看不到任何内容.作为Android开发者,
我通常通过添加android:windowSoftInputMode="adjustResize|stateHidden到清单来修复它.
如何在Flutter中解决它?
码:
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: ListView(
children: <Widget>[
Center(child: Image(image: AssetImage("images/uhk.jpg"))),
Form(
key: formKey,
child: Padding(
padding: EdgeInsets.only(top: 20.0, left: 30.0, right: 30.0),
child: Column(
children: <Widget>[
TextFormField(
decoration:
new InputDecoration(labelText: "P?ihlašovací jméno"),
maxLines: 1,
keyboardType: TextInputType.emailAddress,
onSaved: (String value) => ""),
TextFormField(
decoration: new InputDecoration(labelText: "Heslo"),
maxLines: 1,
obscureText: true,
onSaved: (String value) => ""),
],
),
),
),
Padding(
padding: EdgeInsets.only(top: 50.0, left: 30.0, right: 30.0),
child: …Run Code Online (Sandbox Code Playgroud) 在对话框上,barrierDismissible如果要禁用对话框外部的触摸事件,可以设置为 false。然而,可以仅在屏幕的某些部分监听这些触摸事件,例如。AppBar?
我有一个util Kotlin类,我在其中设置工具栏标题,隐藏或显示工具栏取决于片段:
class MyToolbarUtils() {
fun hideToolbar(activity: Activity) {
(activity as MainActivity).supportActionBar!!.hide()
}
fun showToolbar(activity: Activity, tag: String) {
setToolbarTitle(tag, activity)
(activity as MainActivity).supportActionBar!!.show()
}
fun setToolbarTitle(tag: String, activity: Activity) {
var title = ""
when (tag) {
"Main_fragment" -> title = activity.resources.getString(R.string.Main_screen)
"Add_note" -> title = activity.resources.getString(R.string.Add_note)
}
activity.title = title
}
}
Run Code Online (Sandbox Code Playgroud)
如何从Fragment调用showToolbar(...)?我只是尝试过,MyToolbarUtils.showToolbar(..)但这是不可能的
我发现的唯一方法是:
val setToolbarTitle = MyToolbarUtils()
setToolbarTitle.showToolbar(activity, tag)
Run Code Online (Sandbox Code Playgroud)
但必须有更好的方法来做到这一点..
我正在尝试解决我的应用程序中的表单验证问题。每次单击 TextFromField 时,焦点都会丢失并且键盘隐藏。我发现问题出在“_formKey”上。但我需要它来验证。如何解决?
代码片段:
class _TodoCreateDetailPageState extends State<TodoPage> {
@override
Widget build(BuildContext context) {
final GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
String _title = widget.todo == null ? "New TODO" : widget.todo.title;
String _message;
return new Scaffold(
appBar: new AppBar(
title: new Text(_title),
),
floatingActionButton: new FloatingActionButton(
child: new Icon(Icons.save), onPressed: null),
body: new Padding(
padding: new EdgeInsets.all(20.0),
child: new Form(
key: _formKey,
child: new Column(
children: <Widget>[
new TextField(
decoration: new InputDecoration(labelText: 'Title'),
onChanged: (String value) {
_title …Run Code Online (Sandbox Code Playgroud) 我正在使用 ListView.builder 函数来创建项目列表。然而,iOS 中每个项目之间的空间是巨大的(截图)。你知道如何删除项目吗?似乎是默认的,因为我没有添加它。
代码:
列表显示:
return Scaffold(
body: ListView.builder(
itemCount: data.length,
itemBuilder: (context, index) {
final model = data[index];
if (model.path.isEmpty)
return Divider(color: Colors.grey[500], indent: 40.0);
else
return ItemMenu(model.path, model.name);
}),
);
Run Code Online (Sandbox Code Playgroud)
物品:
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Image.asset(path, width: 100, height: 100,color: Colors.grey[500]),
Text(name, style: MyTextTheme().getLightSmallGrey().copyWith(fontSize: 20.0, fontWeight: FontWeight.w700))
],
);
Run Code Online (Sandbox Code Playgroud)
我想隐藏特定片段中的标签.我有一个MainActivity和两个标签 - 片段(我正在使用viewPager).但是,在第三个片段中,我需要隐藏这些选项卡并仅显示工具栏.
我知道如何隐藏工具栏,但我找不到如何动态隐藏选项卡.
谢谢你的帮助
我有一个片段,我有一个按钮从画廊中选择一个图像.画廊已成功打开,但是当我选择图像时,我无法从活动中获得结果.所以我考虑使用回调(接口).但是,我知道如何.
你能给我一些建议吗?
接口
public interface CallbackListener {
void onPhotoTake(String url);
}
Run Code Online (Sandbox Code Playgroud)
在片段点击
@OnClick(R.id.addPhoto) void photo() {
if (isStoragePermissionGranted()) {
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
context.startActivityForResult(i, RESULT_LOAD_IMAGE);
}
}
Run Code Online (Sandbox Code Playgroud)
活动
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
Run Code Online (Sandbox Code Playgroud)
我想知道如何在 Flutter 中制作平滑的圆角。我发现了一个与 iOS 方法类似的链接 - smooth roundedcorns in swift但它并没有帮助我找到 Flutter 方法的解决方案。我认为ContinuousRectangleBorder就是这样,但这不是我正在寻找的形状。我认为某种剪刀应该有用。
我已经使用改造与 API 进行通信。当用户登录时,我将帐户保存到数据库,当用户下次访问应用程序时,我从数据库获取数据(所以我跳过了登录屏幕)。问题是当用户的令牌过期时。遇到这种情况该如何处理?
在登录片段中的 伪代码
user = ... //get user from database
if(user != null) {
startActivityAccountActivity();
}
//onButtonClick
emailLogin();
Run Code Online (Sandbox Code Playgroud) 我想实现AutocompleteTextView(谷歌地方),但是当我点击片段中的searchView时,片段消失(摔倒).
我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_autocomplete);
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
.setTypeFilter(AutocompleteFilter.TYPE_FILTER_CITIES)
.build();
autocompleteFragment.setFilter(typeFilter);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(com.google.android.gms.location.places.Place place) {
// TODO: handle click
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
}
});
}
Run Code Online (Sandbox Code Playgroud)
XML:
<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:orientation="vertical"
tools:context="ui.screen.activity.AutocompleteActivity">
<fragment
android:id="@+id/place_autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
谢谢你的建议
android google-maps autocompletetextview google-maps-android-api-2