我正在使用Firebase Cloud Messaging发送推送通知.
这是我的FirebaseMessageService:
public class FireBaseMessageService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.e("TAG", "From: " + remoteMessage.getFrom());
Log.e("TAG", "Notification Message Body: " + remoteMessage.getData().get("CardName")+" : "+remoteMessage.getData().get("CardCode"));
sendNotification(remoteMessage.getNotification().getBody());
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, StartActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher_final)
.setContentTitle("Notification")
.setContentText(messageBody)
.setTicker("Test")
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID …Run Code Online (Sandbox Code Playgroud) service android push-notification android-notifications firebase-cloud-messaging
我正在使用此材料对话框库,当我单击肯定按钮时,将onPositive调用该函数并关闭对话框.如何阻止对话框关闭/解除?
谢谢你的回答.
我搜索了很多,但是我没有找到关于如何在RecyclerView中显示SQLite数据的任何分步指南.任何人都可以向我解释我该怎么做?
我的DataBaseAdapter:
public class DataBaseAdapter {
DataBaseHelper helper;
public DataBaseAdapter(Context context) {
helper = new DataBaseHelper(context);
}
public long insertData(String name, String card, String code) {
SQLiteDatabase db = helper.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(DataBaseHelper.NAME, name);
contentValues.put(DataBaseHelper.CARD, card);
contentValues.put(DataBaseHelper.CODE, code);
long id = db.insert(DataBaseHelper.TABLE_NAME, null, contentValues);
return id;
}
public String getData(String name){
//select _id,Name,Card,Code
SQLiteDatabase db = helper.getWritableDatabase();
String[] columns = {DataBaseHelper.NAME, DataBaseHelper.CARD, DataBaseHelper.CODE};
Cursor cursor = db.query(DataBaseHelper.TABLE_NAME, columns,DataBaseHelper.NAME+" = '"+name+"'", null, null, null, null);
StringBuffer buffer …Run Code Online (Sandbox Code Playgroud) 我想搜索RecyclerView,我有List<BaseOfCards> (BaseOfCards是我的getter和setter类)我的RecyclerViewAdapter:
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {
private LayoutInflater inflater;
private List<BaseOfCards> items;
//private int itemLayout;
//String cardvalue;
private Activity mActivity;
public RecyclerViewAdapter(Activity mActivity, Context context, List<BaseOfCards> items) {
this.mActivity = mActivity;
inflater = LayoutInflater.from(context);
this.items = items;
//this.itemLayout = itemLayout;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.custom_row, parent, false);
MyViewHolder holder = new MyViewHolder(view, mActivity);
return holder;
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
BaseOfCards …Run Code Online (Sandbox Code Playgroud) 我的问题很简单,但我无法弄清楚:
当我尝试显示字幕时,工具栏没有足够的空间显示它并且它被剪切.
工具栏:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:layout_centerHorizontal="true"
app:theme="@style/MyToolBar">
Run Code Online (Sandbox Code Playgroud)
难道?android:actionBarSize没有足够的高度,以显示标题和副标题是否正确?
当我将ToolBar高度设置为wrap_content一切正常时,可以有人向我解释我应该如何正确设置高度?
styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/background1</item>
<item name="android:textColorPrimary">@color/colorAccent</item>
<!-- Customize your theme here. -->
</style>
<style name="MyToolBar" parent="Widget.AppCompat.ActionBar">
<!-- Support library compatibility -->
<item name="android:textColorPrimary">@color/colorAccent</item>
<item name="android:textColorSecondary">@color/colorAccent</item>
<item name="colorControlNormal">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我需要启动RecyclerAdapter.class并等待结果,但我不能写行setResult并完成:
public static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView title;
ImageView icon;
public MyViewHolder(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.list_title);
icon = (ImageView) itemView.findViewById(R.id.list_item);
icon.setOnClickListener(this);
}
@Override
public void onClick(View v) {
String selectedCountry;
int country = getPosition();
String ololo = Integer.toString(country);
Log.i("WORKS" ,"??????? ?????? ??? ???????" +ololo);
switch (getPosition()) {
case 0:
selectedCountry = "ukr";
Log.i ("1" ,"" +selectedCountry);
Intent intent= new Intent();
intent.putExtra("country", selectedCountry);
break;
case 1:
selectedCountry = "by";
Log.i ("1" ,"" …Run Code Online (Sandbox Code Playgroud) 我有RecyclerViewAdapter:
public class RecycleViewAdapter extends RecyclerView.Adapter<RecycleViewAdapter.MyViewHolder> {
private List<Cards> items;
private int itemLayout;
Context context;
public RecycleViewAdapter(List<Cards> items, int itemLayout) {
this.items = items;
this.itemLayout= itemLayout;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view=LayoutInflater.from(parent.getContext()).inflate(itemLayout,parent,false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
Cards item=items.get(position);
holder.title.setText(item.getName());
String cardvalue = item.getCountry();
String cardCode = item.getCode();
String cardCountry = item.getCountry();
}
@Override
public int getItemCount() {
return items.size();
}
public static class MyViewHolder extends …Run Code Online (Sandbox Code Playgroud) android android-intent recycler-adapter android-recyclerview