我有一个ReST服务,可以在人员日历中下载有关事件的信息......
当它返回日期和时间时,它将它们作为字符串返回
例如date ="12/8/2012"&time ="11:25 am"
要把它放到android日历中,我需要做以下事情:
Calendar beginTime = Calendar.getInstance();
beginTime.set(year, month, day, hour, min);
startMillis = beginTime.getTimeInMillis();
intent.put(Events.DTSTART, startMillis);
Run Code Online (Sandbox Code Playgroud)
如何拆分日期和时间变量,以便它们在"beginTime.set()"方法中可用?
我刚刚开始使用Fragments,我正在尝试动态添加/替换片段.
我可以添加它们就好了,就像这样......
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
FragmentManager fragMan = getSupportFragmentManager();
FragmentTransaction fragTran = fragMan.beginTransaction();
FragOne fOne = new FragOne();
FragTwo fTwo = new FragTwo();
FragThree fThree = new FragThree();
fragTran.add(R.id.frag_cont_one, fOne);
fragTran.add(R.id.frag_cont_two, fTwo);
fragTran.commit();
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试用fThree替换fTwo时,应用程序崩溃了.继承人我是如何进行替换的
fragTran.replace(R.id.frag_cont_two, fThree);
fragTran.addToBackStack(null);
fragTran.commit();
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢
10-08 21:30:44.710: E/Trace(3219): error opening trace file: No such file or directory (2)
10-08 21:30:44.869: D/AndroidRuntime(3219): Shutting down VM
10-08 21:30:44.869: W/dalvikvm(3219): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
10-08 21:30:44.889: E/AndroidRuntime(3219): FATAL EXCEPTION: …
Run Code Online (Sandbox Code Playgroud) 我在列表视图的顶部有一个搜索栏,并且有一个操作按钮可以切换搜索栏的可见性...
搜索栏显示正确,但是当我隐藏它时,应用程序崩溃了.这是切换视图的代码......
/**
* Show / Hide the search box
*/
private void toggleSearch()
{
//in the instance there are not customers...a crash will occur when searching
if(customers.length > 0)
{
if(searchVisible)//hide the search bar
{
searchFrame.setVisibility(View.GONE);
Log.i("SEARCH", "HIDDEN");
searchVisible = false;
Log.i("SEARCH", "BOOLEAN SET");
resetList();
Log.i("SEARCH", "LIST RESET?");
}
else//show the search bar
{
searchFrame.setVisibility(View.VISIBLE);
searchVisible = true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是LogCat输出......
11-18 11:33:22.483: I/SEARCH(1591): SHOWN
11-18 11:33:22.493: D/audio_hw_primary(183): select_devices: out_snd_device(4: headphones) in_snd_device(0: )
11-18 11:33:22.753: D/audio_hw_primary(183): out_set_parameters: enter: …
Run Code Online (Sandbox Code Playgroud) 我有一个listView,其中包含项目,我想实现过滤器(名称,价格,类型等)
我想创建一个"过滤列表",它等于原始列表的相反顺序
但是当我这样做的时候......
List<String> itemsList = new ArrayList<String>();
List<String> filterList = new ArrayList<String>();
filterList = Collections.reverse(itemsList);
Run Code Online (Sandbox Code Playgroud)
我得到"类型不匹配:无法从void转换为List"
在我的应用程序中,我正在从ReST Web服务下载JSON数据。在大多数情况下,这可以正常工作,但是有时连接会超时。
这是我用来设置超时的代码...
HttpConnectionParams.setConnectionTimeout( httpParameters, 20000 );
HttpConnectionParams.setSoTimeout( httpParameters, 42000 );
Run Code Online (Sandbox Code Playgroud)
如果连接超时,应用程序崩溃并关闭,我该如何处理超时?
我试图从设备外部目录中读取.json文件.
我有一个名为ExternalFile的类,用于读取文件并将内容作为字符串返回.
这是班级:
public class ExternalFile
{
final String EXTERNAL_STORAGE = Evironment.getExternalStorageDirectory().toString();
final String FIRSTDROID_DIRECTORY = EXTERNAL_STORAGE + "/firstdroid/";
final String SALES_DIRECTORY = FIRSTDROID_DIRECTORY + "sales/";
final String REFERENCE_DIRECTORY = FIRSTDROID_DIRECTORY + "reference/";
public String readFile(String direcectory, String fileName)
{
BufferedReader br;
StringBuilder sBuffer;
File JSON;
String line;
String retVal = null;
try
{
sBuffer = new StringBuilder();
JSON = new File(direcectory, fileName);
br = new BufferedReader(new FileReader(JSON));
while ((line = br.readLine()) != null)
{
sBuffer.append(line);
sBuffer.append('\n');
}
retVal = …
Run Code Online (Sandbox Code Playgroud)