我是一名Android学员.我想学习RxJava.我的问题是"RxJava中的CompositeDisposable是什么?".请详细说明.
我试图在Activity点击通知时打开,下面是我的代码.
Intent intent = new Intent(this.getApplicationContext(), NotificationActivity.class);
intent.putExtra("msgBody",messageBody);
intent.putExtra(Constants.NOTIF_INTENT_TYPE,Constants.NOTIF_INTENT_TYPE);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|Intent.FLAG_ACTIVITY_SINGLE_TOP
|Intent.FLAG_ACTIVITY_CLEAR_TOP); //Tried with many options here
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 , intent,
PendingIntent.FLAG_CANCEL_CURRENT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.otp_icon)
.setContentTitle("Push MSG")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
Run Code Online (Sandbox Code Playgroud)
Android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.com.pushapp">
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="21" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".AndroidPushApp" …Run Code Online (Sandbox Code Playgroud) java android push-notification firebase-cloud-messaging firebase-notifications
我正在使用一个Android应用程序,它使用蓝牙连接在我的Android智能手机和非Android蓝牙模块之间传输数据,使用SPP配置文件.我使用Android Developer网站的蓝牙聊天示例作为参考.
我已经成功地将两个设备相互连接,并将简单的字符串从智能手机发送到蓝牙模块.但是我在读取从模块发回的数据时遇到了一些错误.我使用以下代码,与蓝牙聊天示例完全相同,从InputStream读取数据
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
String str = new String(buffer);
Log.i(TAG, "mmInStream - " + str);
// Send the obtained bytes to the UI Activity
mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes, -1, buffer)
.sendToTarget();
} catch (IOException e) {
Log.e(TAG, "disconnected", e);
connectionLost();
break;
}
}
Run Code Online (Sandbox Code Playgroud)
当我的蓝牙模块向手机发送一个简单的字符串时,没有正确接收该字符串.它以随机的方式分成几个部分.例如,如果我将三次"1234567890abcdef1234567890abcdef0123456789"发送到手机,Eclipse上的Logcat将记录这些:
mmInstream - 12345678910abcdef????????(continuing null)
mmInstream - 1????????(continuing null)
mmInstream - 2345678910abcdef0123456789????????(continuing null)
Run Code Online (Sandbox Code Playgroud)
首次.在第二次和第三次传输数据时,它会收到差异:
mmInstream - 1234567891???????(continuing null)
mmInstream - 0abcdef012???????(continuing null)
mmInstream - 3456789?????????(continuing null)
mmInstream …Run Code Online (Sandbox Code Playgroud) 我使用多个屏幕RecyclerView,也有一个小的Fragment是对的顶部RecyclerView.当Fragment显示时,我想确保我可以滚动到底部RecyclerView.在Fragment并不总是显示.如果我使用了边距,RecyclerView我需要动态删除并在Fragment显示时添加它们.我可以将余量添加到列表中的最后一项,但这也很复杂,如果我稍后加载更多东西(即分页),我将不得不再次剥离这些边距.
如何动态添加或删除视图边距?有什么其他选择来解决这个问题?
编辑:
glide以前加载图像.我到了Out of Memory Error.我在清单中使用了大堆true :
android:largeHeap="true"
Run Code Online (Sandbox Code Playgroud)
滑翔版:
compile 'com.github.bumptech.glide:glide:3.7.0'
Run Code Online (Sandbox Code Playgroud)
设备/ Android版本:
Nexus Device 6.0版本
我从Json得到的每张图片都是800kb到1mb.
activity_layout:
<RelativeLayout
android:id="@+id/home_layout_bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/home_layout_top_recycler"
android:layout_margin="5dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_list_tab_home_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical"
android:visibility="visible" />
<TextView
android:id="@+id/no_user_posts_item_tv_recycler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/rv_list_tab_home_recycler"
android:layout_marginTop="80dp"
android:layout_centerHorizontal="true"
android:text="@string/txt_no_posts_available"
android:textColor="@color/txt_common_black"
android:textSize="@dimen/txt_size" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
适配器代码:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
final HomePostItems rowItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) { …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,有两种方法getData和getItemsByLabel.每个人都得到不同的列表,我使用了导航抽屉方法,onNavigationItemSelected这样每当用户点击某个特定项目时,就会显示一个不同的列表RecyclerView.问题是我使用一种方法addOnScrollListener来检测任何列表中的滚动行为RecyclerView,导致项目在显示的列表中重叠.
因此问题在于当向下滚动时,主列表中的项目和所选类别/项目的列表是重叠的.
这是我的代码.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Fabric.with(this, new Crashlytics());
// Crashlytics.logException(new Exception("My first Android non-fatal error"));
// I'm also creating a log message, which we'll look at in more detail later
// Crashlytics.log("MainActivity started");
swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
recyclerView = findViewById(R.id.recyclerView);
manager = new LinearLayoutManager(this);
emptyView = (TextView) findViewById(R.id.empty_view);
progressBar = findViewById(R.id.spin_kit);
adapter = new PostAdapter(this, items);
recyclerView.setLayoutManager(manager);
recyclerView.setAdapter(adapter);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false); …Run Code Online (Sandbox Code Playgroud) java android onscrolllistener android-recyclerview retrofit2
我目前正致力于复制Play商店应用中实现的UI模式.为了实现这样的行为,我使用了Vertical RecyclerView作为外部视图,并RecyclerView在外部Vertical的适配器内添加了一个水平RecyclerView.
我目前面临的问题是当外部RecyclerView滚动时,内部水平RecyclerView不能捕捉到滚动事件,但是当外部RecyclerView不滚动时,我们可以RecyclerView平滑地滚动水平.
如果有人可以提供帮助,请留下您的评论.Cou可以测试Play商店中的功能RecyclerView,即使外部RecyclerView滚动,也可以启用内部水平滚动.
Play商店应用:
这是我的网络请求示例
networkAPI.postData(myData).enqueue(new Callback<MyResponse>() {
@Override
public void onResponse(Call<MyResponse> call, Response<MyResponse> response) {
if (response.code() == 201) {
// success
}
}
@Override
public void onFailure(Call<MyResponse> call, Throwable t) {
}
});
Run Code Online (Sandbox Code Playgroud)
这是我应该只拨打一次的请求,因为我有一次可用的优惠券代码.如果我立即关闭我的网络连接或者在调用此方法后立即断开连接,那么它会移动到onFailure带有IOExceptionthrowable的方法,这通常是指连接错误,但重点是发布到服务器的数据和使用的凭证代码,问题是onFailure方法在这里被称为.
我确信它不是解析失败,因此我也尝试使用它Void.为什么onResponse即使在发布数据后也没有调用.如何克服这种情况?
我有这样的RecyclerView行布局
<Layout>
<BackgroundView>
<ForegroundView>
</Layout>
Run Code Online (Sandbox Code Playgroud)
我ItemTouchHelper用来处理前景视图上的滑动(部分)
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
adapter.onItemSwiped(viewHolder);
}
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
float dX, float dY, int actionState, boolean isCurrentlyActive) {
View foregroundView = ((myViewHolder)viewHolder).getForegroundView();
getDefaultUIUtil().onDraw(c, recyclerView, foregroundView, dX, dY, actionState, isCurrentlyActive);
//getSwipeLimit() used below returns the width of the delete icon
float translationX = Math.min(-dX, ((myViewHolder) viewHolder).getSwipeLimit());
foregroundView.setTranslationX(-translationX);
}
Run Code Online (Sandbox Code Playgroud)
我在BindViewHolder我的适配器类中为backgroundview设置了一个单击侦听器.
@Override
public void onBindViewHolder(WhiteListViewHolder holder, Cursor cursor) {
//get name …Run Code Online (Sandbox Code Playgroud) 我使用RecyclerView适配器来显示活动内部的数据,我想onClickListener在活动内部实现,目前,我onClickListener正常设置内部适配器,工作正常.
public void onBindViewHolder(MyHolder holder, final int position) {
final Listdata data = listdata.get(position);
holder.vname.setText(data.getName());
holder.vname.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(activity, "clicked on " +position, Toast.LENGTH_SHORT).show();
}
});
}
Run Code Online (Sandbox Code Playgroud)
但是我想在活动中实现它,所以我有更大的控制权.这不符合我的目的.我认为这对我们很多人都有用.