在使用ListView
自定义适配器的旧代码中,我可以使用此代码获取项目.
Message msg = (Message) adapter.getItem(poistion);
Run Code Online (Sandbox Code Playgroud)
现在我正在实施RecyclerView
.我如何从中获取物品RecyclerView.adapter
?
在我们的应用程序,我们使用EditText
带有TextInputLayout
显示验证错误.在我们更新到最新的支持库之前,一切正常com.android.support:design:23.2.0
.此更新后,应用程序在尝试显示错误时开始崩溃.布局:
<android.support.design.widget.TextInputLayout
android:id="@+id/name_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:counterMaxLength="100"
>
<EditText
android:id="@+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/group_name"
android:inputType="textMultiLine|textCapWords"
android:textSize="16sp"/>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
码:
nameLayout.setError("Error);
nameEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
nameLayout.setError(null);
}
}
});
Run Code Online (Sandbox Code Playgroud)
错误:
FATAL EXCEPTION: main
Process: im.grouvi.app.debug, PID: 10704
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 3: TypedValue{t=0x2/d=0x7f01010b …
Run Code Online (Sandbox Code Playgroud) 我已经查看了其他问题,博客和文档,似乎无法找到满足我需求的正确答案.我有两个活动,A和B.当我启动活动B(来自A)时,我希望它立即打开,然后在显示进度条时加载所有内容,而不是仅在加载内容时打开活动,使其成为可能好像它冻结了两秒钟.例如Youtube应用程序或Play商店.
这就是我得到的:
Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent goB = new intent(ActivityA.this, ActivityB.class);
startActivity(goB);
}
});
Run Code Online (Sandbox Code Playgroud)
这是我正在加载的活动:
public class ActivityB extends AppCompatActivity implements OnDateSelectedListener, OnMonthChangedListener {
private static final DateFormat FORMATTER = SimpleDateFormat.getDateInstance();
@Bind(R.id.calendarView) MaterialCalendarView widget;
@Bind(R.id.textView) TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_c_calendar);
ButterKnife.bind(this);
widget.setOnDateChangedListener(this);
widget.setOnMonthChangedListener(this);
textView.setText(getSelectedDatesString());
}
@Override
public void onDateSelected(@NonNull MaterialCalendarView widget, @Nullable CalendarDay date, boolean selected) {
textView.setText(getSelectedDatesString());
}
private String getSelectedDatesString() {
CalendarDay date = widget.getSelectedDate();
if (date …
Run Code Online (Sandbox Code Playgroud) 在我们的应用程序中,我使用此代码下载图像文件.我需要在UI上显示下载进度(以百分比形式下载的字节数).我如何在此代码中获得下载进度?我搜索了解决方案,但仍无法自行完成.
Observable<String> downloadObservable = Observable.create(
sub -> {
Request request = new Request.Builder()
.url(media.getMediaUrl())
.build();
Response response = null;
try {
response = http_client.newCall(request).execute();
if (response.isSuccessful()) {
Log.d(TAG, "response.isSuccessful()");
String mimeType = MimeTypeMap.getFileExtensionFromUrl(media.getMediaUrl());
File file = new File(helper.getTmpFolder() + "/" + helper.generateUniqueName() + "test." + mimeType);
BufferedSink sink = Okio.buffer(Okio.sink(file));
sink.writeAll(response.body().source());
sink.close();
sub.onNext(response.toString());
sub.onCompleted();
} else {
sub.onError(new IOException());
}
} catch (IOException e) {
e.printStackTrace();
}
}
);
Subscriber<String> mySubscriber = new Subscriber<String>() {
@Override
public void …
Run Code Online (Sandbox Code Playgroud) 在应用程序中,我希望获得唯一的手机ID TelephonyManager.getDeviceId()
.要使用它,我需要此权限READ_PHONE_STATE
.问题在于Android 6的运行时权限.在运行时权限弹出对话框中,它要求授予"制作和管理电话"权限,这可能会吓到用户使用应用程序.可以做些什么?或者,如果不使用如此大的权限,我可以获得设备的任何其他唯一标识符
TelephonyManager TM = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String deviceId = TM.getDeviceId();
Run Code Online (Sandbox Code Playgroud) 我需要在 Jetpack Compose Text 中制作中间省略号。据我所知,TextOverflow 只有 Clip、Ellipsis 和 Visible 选项。像这样的事情: 4gh45g43h...bh4bh6b64
在我们的应用程序中,我们有消息列表.我们正在转向RecyclerView
.我们的消息可以包括文本,图像.示例消息可能如下所示.
要处理点击,请使用此类:
public class RecyclerViewItemClickListener implement RecyclerView.OnItemTouchListener {
public static interface OnItemClickListener {
public void onItemClick(View view, int position);
public void onItemLongClick(View view, int position);
}
private OnItemClickListener mListener;
private GestureDetector mGestureDetector;
public RecyclerViewItemClickListener(Context context, final RecyclerView recyclerView, OnItemClickListener listener) {
mListener = listener;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
@Override
public void onLongPress(MotionEvent e)
{
View childView = recyclerView.findChildViewUnder(e.getX(), e.getY());
if(childView != null && mListener != null) …
Run Code Online (Sandbox Code Playgroud) 自定义始终以Tablayout为中心.tablayout如下.如何获得其父级可用的完整空间,即TabView.
<android.support.design.widget.TabLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tablayout"
android:layout_width="match_parent"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
android:layout_height="90dp">
</android.support.design.widget.TabLayout>
Run Code Online (Sandbox Code Playgroud)
添加如下所示的textview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_purple"
android:gravity="center_horizontal">
<TextView
android:text="Hello !"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
但不幸的是,它总是居中,永远不会占据整个空间.问题是我不能在标签之间提供分隔符,因为它始终位于中心.
用于添加标签的Java代码:
TabLayout v = (TabLayout)findViewById(R.id.tablayout);
TabLayout.Tab tab = v.newTab();
tab.setCustomView(R.layout.content_main);
v.addTab(tab);
tab = v.newTab();
tab.setCustomView(R.layout.content_main);
v.addTab(tab);
tab = v.newTab();
tab.setCustomView(R.layout.content_main);
v.addTab(tab)
Run Code Online (Sandbox Code Playgroud)
我分享了这张图片@ http://i60.tinypic.com/11cdvyf.jpg
对于推送通知,我们使用GCM(Google云消息传递).当我们使用播放服务时它工作正常:8.3.0.我们使用自己的接收器处理推送通知.升级到com.google.android.gms:play-services:8.4.0
Push后不到我的myGcmListenerService,而是在通知栏中单独显示.它还在Log中显示此错误
GcmAnalytics: Error while parsing timestamp in GCM event.
在8.3.0中,我们收到了这样的推送:
Bundle[{gcm.notification.e=1, google.c.a.ts=234343426, gcm.notification.badge=1, gcm.notification.sound=default, gcm.notification.sound2=default, gcm.notification.body=John M @ Cords, Wires And Cable Ftu, gcm.notification.data={"name":"new_chat_message","message_id":490666,"channel_id":5366}, google.c.a.e=1, collapse_key=com.domain.app.debug}]
8.4.0推送就像这样:
Bundle[{notification=Bundle[{sound2=default, e=1, body=John M @ Cords, Wires And Cable Rrr, data={"name":"new_chat_message","message_id":490641,"channel_id":5366}, badge=1, sound=default}], collapse_key=com.domain.app.debug}]
android push-notification google-cloud-messaging google-play-services
在我的RSS阅读器项目中,我需要不同大小的项目(包含图像和文本).
我搜索了在Android中制作Staggered Grid的解决方案,并且遇到了Etsy的AndroidStaggeredGrid库.我正在使用Eclipse,但库是为Gradle完成的.
我想在我的Android项目中使用这个库.我已经尝试过这个答案但是没有成功.如何将此库导入我的Android项目.