任何人都能解释一下我在处理日历活动时使用的每个术语吗?
Uri event_uri = Uri.parse("content://com.android.calendar/" + "events");
什么是uri,实际上是什么内容,因为我们可以将int值初始化为0?是否
可以使用默认值初始化uri?
Uri reminder_uri = Uri.parse("content://com.android.calendar/" + "reminders");
什么意味着这些uri?event_uri
和之间有什么区别reminder_uri
?
ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", str);
values.put("description", m_strDescription);
第一个做什么? values.put("calendar_id", 1);
ContentResolver cr = getContentResolver();
内容解析器有什么用?有时我们会写:
Uri u = cr.insert(event_uri, values)
这是什么uri?它与前两个uris有何不同,例如event_uri
和reminder_uri
再次 values.put("event_id", Long.parseLong(event.getLastPathSegment()));
cr.insert(remindar_uri, values);
它有什么作用?
我有一个TextView
,我想要的是制作TextView
形状圆,然后根据我使用的不同条件设置不同的背景颜色.我可以根据不同的条件设置背景颜色,但不能制作TextView
形状圆.那怎么可以做到.请帮我解决这个问题.
我用的代码是
TextView txt_stage_display = (TextView)findViewById(R.id.txt_stage_display);
if(m_enStage[position] == enSTAGE_START)
{
txt_stage_display.setBackgroundColor(Color.parseColor("#D48393"));
}
else if(m_enStage[position] == enSTAGE_FLOW)
{
txt_stage_display.setBackgroundColor(Color.parseColor("#D48393"));
}
else if(m_enStage[position] == enSTAGE_SAFE)
{
txt_stage_display.setBackgroundColor(Color.parseColor("#66B0CC"));
}
else if(m_enStage[position] == enSTAGE_UNSAFE)
{
txt_stage_display.setBackgroundColor(Color.parseColor("#D8C627"));
}
else if(m_enStage[position] == enSTAGE_FERTILE)
{
txt_stage_display.setBackgroundColor(Color.parseColor("#67A05E"));
}
else
{
txt_stage_display.setBackgroundColor(Color.parseColor("#808080"));
}
Run Code Online (Sandbox Code Playgroud) 我有一个numberDecimal EditText
,我想用正则表达式验证.在验证中我想要的是:
在小数点之前,我要输入的最大数字是3,数字不应该像零一样从零开始2,23,342
,等等.
小数点后,我想进入的最大数字是一个像.1
,.3
,.6
等等.
所以,我允许用户输入的数字一样2.1
,32.5
,444.8
,564.9
,等.
但在我的代码中,会发生什么:
它允许用户在小数点前输入超过三位数更像是3456
,4444
,5555
之后,它不会让我以后输入小数点.
它允许我0
在小数点之前输入数字的开头.
那么为什么会发生这种情况,我使用的正则表达式有什么不对吗?如果有人知道,请帮我解决这个问题.
我用过的代码:
weightEditText.addTextChangedListener(new TextWatcher()
{
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s)
{
Pattern mPattern = Pattern.compile("^([1-9][0-9]{0,2})?(\\.[0-9]?)?$");
Matcher matcher = mPattern.matcher(s.toString());
if(!matcher.find())
{ …
Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用TimePicker.每当用户使用TimePicker打开屏幕时,我会使用当前时间对其进行初始化.当我这样做时,TimePicker显示AM而不是PM.为什么会这样?我的代码中有什么必须添加的吗?
Date initDate = m_NoteManageObject.getDateTimeArray(position);
Calendar myCal = Calendar.getInstance();
myCal.setTime(initDate);
TimePicker timePicker = (TimePicker)layout.findViewById(R.id.time_picker);
// Initialise Time Picker
timePicker.setCurrentHour(myCal.get(Calendar.HOUR));
timePicker.setCurrentMinute(myCal.get(Calendar.MINUTE));
Run Code Online (Sandbox Code Playgroud) 我创建了一个活动,其中我使用共享首选项来存储数据..现在在另一个活动中我有一个重置按钮..当我点击重置按钮时,数据存储将丢失..所以如何做到这一点..我的代码是
activity1中的代码:
public void writeToRegister()
{
// Write history data to register
SharedPreferences preferences1 = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor1 = preferences1.edit();
editor1.putInt("iHistcount", CycleManager.getSingletonObject().iHistCount);
for(int i=0;i< CycleManager.getSingletonObject().iHistCount;i++)
{
editor1.putLong("dtHistoryDate"+Integer.toString(i), CycleManager.getSingletonObject().dtHistory[i].getTime());
}
editor1.commit();
}
public void readFromRegister()
{
// Read history data from register
SharedPreferences preferences1 = getPreferences(MODE_PRIVATE);
CycleManager.getSingletonObject().iHistCount=preferences1.getInt("iHistcount", 0);
for(int i=0;i< CycleManager.getSingletonObject().iHistCount;i++)
{
Long x=preferences1.getLong("dtHistoryDate"+Integer.toString(i), 0L);
CycleManager.getSingletonObject().dtHistory[i]=new Date(x);
}
}
Run Code Online (Sandbox Code Playgroud)
活动2的代码:
Button pBtnReset = new Button(this);
pBtnNextMonth.setOnClickListener(pBtnReset OnClickListener);
Button.OnClickListener pBtnReset OnClickListenernew Button.OnClickListener()
{
public void onClick(View arg0)
{
}
};
Run Code Online (Sandbox Code Playgroud)
所以我必须在第二个活动重置按钮中写入,以便清除存储的数据
是否可以使用存储Date
对象SharedPreferences
?
实际上在我的代码中我有一个String
变量,boolean
和Date
.这是我存储除了以外的所有对象的函数Date
.那么如何做呢请建议我?
private void SavePreferences() {
String key="1";
String value="hello";
int x=5;
Date currentDate=new Date();
SharedPreferences sharedPreferences = getPreferences(MODE_APPEND);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.putInt("2",5);
editor.commit();
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是如何存储Date
使用SharedPreferences
?
在我们的应用程序中,我们处理按钮中的事件以记录数据.
所以最初当我使用setOnLongClickListener()
和setOnClickListener()
使用相同的按钮时,它对我们来说很好.
这意味着它将基于Click和LongClick按钮调用此侦听器.现在,当我尝试使用setOnTouchListener()
相同的按钮setOnLongClickListener()
,setOnClickListener()
然后只有OnTouch事件正在工作,休息onclick和onLongclick事件不起作用.
任何人都可以告诉我为什么会发生这种情况,如果可能的话,请举例说明
我使用的代码是..
Button btnAdd=new Button(this)
btnAdd.setOnLongClickListener(this);
btnAdd.setOnClickListener(this);
btnAdd.setOnTouchClickListener(this);
public void onClick(View v)
{
//Statements;
}
public void onLongClick(View v)
{
//Statements;
}
public boolean onTouch(View v, MotionEvent e)
{
switch (e.getAction())
{
case MotionEvent.ACTION_DOWN:
{
//store the X value when the user's finger was pressed down
m_downXValue = e.getX();
break;
}
case MotionEvent.ACTION_UP:
{
//Get the X value when the user released his/her finger
float currentX = …
Run Code Online (Sandbox Code Playgroud) 我使用我的应用程序的集合创建了一个应用程序小部件,该小部件显示该特定日期的日期和项目列表.一切正常,窗口小部件正在根据需要进行更新.但有时,通过单击下一个和上一个按钮更改窗口小部件中的日期时会发生什么,列表不刷新意味着项目在该特定日期未更新.此行为是随机的,有时仅发生.那么为什么会发生这种情况,我的代码中有任何错
我使用的代码是:
WidgetProvider.class
public class WidgetProvider extends AppWidgetProvider
{
private ThemeManager m_ThemeManagerObject;
private static String WIDGET_NEXT_BUTTON = "in.test.widgetApp.WIDGET_NEXT_BUTTON";
private static String WIDGET_PREV_BUTTON = "in.test.widgetApp.WIDGET_PREV_BUTTON";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
super.onUpdate(context, appWidgetManager, appWidgetIds);
// Set Date to current Date
NoteManager.getSingletonObject().setWidgetToCurrentDate();
// Code to update the widget by current date
updateAppWidget(context, AppWidgetManager.getInstance(context), appWidgetIds);
}
@Override
public void onReceive(Context context, Intent intent)
{
super.onReceive(context, intent);
int numOfDays = 1;
ComponentName thisWidget = new ComponentName(context, WidgetProvider.class);
AppWidgetManager appWidgetManager = …
Run Code Online (Sandbox Code Playgroud) 删除Android SD卡上的图像时,有时图像被正确删除但在图库中仍然保留已删除图像的预览.点击它时,它将作为黑色图像加载.要解决此问题,您需要运行MediaScanner.但是此代码不起作用,并且评论图像的预览仍保留在图库中.
任何人都知道如何解决这个问题
Uri contentUri = Uri.fromFile(file);
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,contentUri);
sendBroadcast(mediaScanIntent);
Run Code Online (Sandbox Code Playgroud) 实际上我已经创建了一个应用程序,它的工作正常.但是假设我调试我的应用程序,并以某种方式调试我的设备锁定.现在当我解锁我的设备崩溃并显示ANR(活动无响应).我看看logcat,但无法从那里得到任何线索.所以请帮我解决这个问题.我的logcat如下:
03-16 16:54:46.117: E/ActivityManager(114): ANR in in.plackal.lovecyclesfree
03-16 16:54:46.117: E/ActivityManager(114): Reason: Broadcast of Intent { act=android.intent.action.SCREEN_OFF flg=0x40000000 }
03-16 16:54:46.117: E/ActivityManager(114): Load: 1.49 / 1.23 / 1.28
03-16 16:54:46.117: E/ActivityManager(114): CPU usage from 5083ms to 0ms ago:
03-16 16:54:46.117: E/ActivityManager(114): 2.5% 114/system_server: 1.5% user + 0.9% kernel / faults: 3 minor
03-16 16:54:46.117: E/ActivityManager(114): 0% 14/kondemand/0: 0% user + 0% kernel
03-16 16:54:46.117: E/ActivityManager(114): 0% 49/file-storage: 0% user + 0% kernel
03-16 16:54:46.117: E/ActivityManager(114): 0.1% 182/com.android.systemui: 0.1% user + 0% …
Run Code Online (Sandbox Code Playgroud)