用到的技术:bmob后端云、ListVIEw
运行效果图:
项目结构图:
首先要配置好bmob的环境:https://www.cnblogs.com/hemeiwolong/p/12874714.html
剩下的看源码
manifests:
1 <?xml version="1.0" enCoding="utf-8"?> 2 <manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" 3 package="com.mingrisoft.cooking"> 4 <!--允许联网 --> 5 <uses-permission androID:name="androID.permission.INTERNET" /> 6 <!--获取GSM(2g)、WCDMA(联通3g)等网络状态的信息 --> 7 <uses-permission androID:name="androID.permission.ACCESS_NETWORK_STATE" /> 8 <!--获取wifi网络状态的信息 --> 9 <uses-permission androID:name="androID.permission.ACCESS_WIFI_STATE" />10 <!--保持cpu 运转,屏幕和键盘灯有可能是关闭的,用于文件上传和下载 -->11 <uses-permission androID:name="androID.permission.WAKE_LOCK" />12 <!--获取sd卡写的权限,用于文件上传和下载-->13 <uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE" />14 <!--允许读取手机状态 用于创建BmobInstallation-->15 <uses-permission androID:name="androID.permission.READ_PHONE_STATE" />16 17 <application18 androID:allowBackup="true"19 androID:icon="@mipmap/ic_launcher"20 androID:label="@string/app_name"21 androID:roundIcon="@mipmap/ic_launcher_round"22 androID:supportsRtl="true"23 androID:theme="@style/Apptheme">24 <activity androID:name=".MainActivity">25 <intent-filter>26 <action androID:name="androID.intent.action.MAIN" />27 28 <category androID:name="androID.intent.category.LAUNCHER" />29 </intent-filter>30 </activity>31 32 <provIDer33 androID:name="cn.bmob.v3.util.BmobContentProvIDer"34 androID:authoritIEs="com.mingrisoft.cooking.BmobContentProvIDer"> //这里要改为自己的包名35 </provIDer>36 </application>37 38 </manifest>
activity_main.xml:
1 <?xml version="1.0" enCoding="utf-8"?> 2 <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" 3 xmlns:app="http://schemas.androID.com/apk/res-auto" 4 xmlns:tools="http://schemas.androID.com/tools" 5 androID:layout_wIDth="match_parent" 6 androID:layout_height="match_parent" 7 androID:orIEntation="vertical" 8 tools:context=".MainActivity"> 9 10 <relativeLayout11 androID:layout_wIDth="match_parent"12 androID:layout_height="wrap_content">13 14 <ImageVIEw15 androID:ID="@+ID/iv_hf_cook"16 androID:layout_wIDth="wrap_content"17 androID:layout_height="wrap_content"18 androID:adjustVIEwBounds="true"19 androID:maxWIDth="100dp"20 androID:maxHeight="100dp"21 androID:src="@drawable/cooking"/>22 23 <TextVIEw24 androID:ID="@+ID/tv_hf_Title"25 androID:layout_toRightOf="@+ID/iv_hf_cook"26 androID:text="厨艺讨论区"27 androID:textSize="20sp"28 androID:textStyle="bold"29 androID:layout_wIDth="match_parent"30 androID:layout_height="wrap_content" />31 32 <TextVIEw33 androID:layout_toRightOf="@+ID/iv_hf_cook"34 androID:layout_below="@+ID/tv_hf_Title"35 androID:layout_wIDth="wrap_content"36 androID:layout_height="wrap_content"37 androID:text="论坛介绍ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff38 fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"/>39 </relativeLayout>40 41 <VIEw42 androID:layout_wIDth="match_parent"43 androID:layout_height="5px"44 androID:background="#dadef7"></VIEw>45 46 <ScrollVIEw47 androID:layout_wIDth="match_parent"48 androID:layout_height="wrap_content">49 </ScrollVIEw>50 51 <ListVIEw52 androID:ID="@+ID/lv_hf_ListvIEw"53 androID:layout_wIDth="match_parent"54 androID:layout_height="300dp"55 androID:divIDerHeight="5dp"56 androID:layout_weight="1">57 </ListVIEw>58 59 <VIEw60 androID:layout_wIDth="match_parent"61 androID:layout_height="5px"62 androID:background="#dadef7"></VIEw>63 64 <linearLayout65 androID:layout_wIDth="match_parent"66 androID:layout_height="wrap_content">67 68 <EditText69 androID:ID="@+ID/et_hf_content"70 androID:layout_wIDth="match_parent"71 androID:layout_height="wrap_content"72 androID:hint="发表东西吧"73 androID:maxlines="2"74 androID:layout_weight="1"/>75 76 <button77 androID:ID="@+ID/btn_hf_send"78 androID:layout_wIDth="wrap_content"79 androID:layout_height="wrap_content"80 androID:text="发送"/>81 </linearLayout>82 83 </linearLayout>
content.xml:
1 <?xml version="1.0" enCoding="utf-8"?> 2 <relativeLayout 3 xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" 4 androID:layout_height="match_parent"> 5 6 <VIEw 7 androID:ID="@+ID/splitline" 8 androID:layout_wIDth="match_parent" 9 androID:layout_height="5px"10 androID:paddingtop="10dp"11 androID:paddingBottom="10dp"12 androID:background="#dadef7"></VIEw>13 14 <ImageVIEw15 androID:ID="@+ID/headImage"16 androID:layout_below="@+ID/splitline"17 androID:layout_wIDth="wrap_content"18 androID:layout_height="wrap_content"19 androID:src="@drawable/register"20 androID:maxHeight="100dp"21 androID:adjustVIEwBounds="true"22 androID:maxWIDth="100dp"/>23 24 <TextVIEw25 androID:ID="@+ID/content_name"26 androID:maxWIDth="100dp"27 androID:layout_below="@+ID/headImage"28 androID:layout_wIDth="wrap_content"29 androID:layout_height="wrap_content"30 androID:text="hemeiwolong"/>31 32 <TextVIEw33 androID:ID="@+ID/content_date"34 androID:layout_below="@+ID/content_name"35 androID:layout_wIDth="wrap_content"36 androID:layout_height="wrap_content"37 androID:maxWIDth="100dp"38 androID:text="xxxx/xx/xx hh:mm:ss"/>39 40 <TextVIEw41 androID:ID="@+ID/content_content"42 androID:layout_marginleft="110dp"43 androID:layout_wIDth="match_parent"44 androID:layout_height="wrap_content"45 androID:text="fffffffffffffffffffffffffffffffffff46 "/>47 48 </relativeLayout>
CookContent:
1 package com.mingrisoft.cooking; 2 3 import cn.bmob.v3.BmobObject; 4 5 public class CookContent extends BmobObject { 6 private String name; 7 private String date; 8 private String content; 9 10 public String getname() {11 return name;12 }13 public voID setname(String name) {14 this.name = name;15 }16 public String getDate() {17 return date;18 }19 public voID setDate(String address) {20 this.date = address;21 }22 23 public String getContent() {24 return content;25 }26 public voID setContent(String content) {27 this.content = content;28 }29 }
MainActivity:
1 package com.mingrisoft.cooking; 2 3 import androID.app.Activity; 4 import androID.support.v7.app.AppCompatActivity; 5 import androID.os.Bundle; 6 import androID.util.Log; 7 import androID.vIEw.VIEw; 8 import androID.Widget.button; 9 import androID.Widget.EditText; 10 import androID.Widget.ListVIEw; 11 import androID.Widget.SimpleAdapter; 12 import androID.Widget.Toast; 13 14 import java.text.SimpleDateFormat; 15 import java.util.ArrayList; 16 import java.util.Date; 17 import java.util.HashMap; 18 import java.util.List; 19 import java.util.Map; 20 21 import cn.bmob.v3.Bmob; 22 import cn.bmob.v3.Bmobquery; 23 import cn.bmob.v3.datatype.BmobqueryResult; 24 import cn.bmob.v3.exception.BmobException; 25 import cn.bmob.v3.Listener.FindListener; 26 import cn.bmob.v3.Listener.sqlqueryListener; 27 import cn.bmob.v3.Listener.SaveListener; 28 29 public class MainActivity extends Activity { 30 31 @OverrIDe 32 protected voID onCreate(Bundle savedInstanceState) { 33 super.onCreate(savedInstanceState); 34 setContentVIEw(R.layout.activity_main); 35 36 //初始化 Bmob SDK,第一个参数为上下文,第二个参数为Application ID 37 Bmob.initialize(this, "1368b7fd0a523efab971eb807e1b9bc2"); 38 39 button send = findVIEwByID(R.ID.btn_hf_send); 40 EditText et_hf_content = findVIEwByID(R.ID.et_hf_content); 41 ListVIEw ListVIEw = findVIEwByID(R.ID.lv_hf_ListvIEw); 42 43 Bmobquery<CookContent> query = new Bmobquery<CookContent>(); 44 45 String bql ="select * from CookContent";//查询所有的游戏得分记录 46 new Bmobquery<CookContent>().dosqlquery(bql,new sqlqueryListener<CookContent>(){ 47 48 @OverrIDe 49 public voID done(BmobqueryResult<CookContent> result, BmobException e) { 50 if(e ==null){ 51 List<CookContent> List = (List<CookContent>) result.getResults(); 52 if(List!=null && List.size()>0){ 53 ArrayList<Map<String, String>> resultList = new ArrayList<>(); 54 55 for (CookContent cookContent : List) { 56 Map<String, String> map = new HashMap<>(); 57 map.put("name", cookContent.getname()); 58 map.put("date", cookContent.getDate()); 59 map.put("content", cookContent.getContent()); 60 resultList.add(map); 61 } 62 63 SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, resultList, 64 R.layout.content, new String[]{"name", "date", "content"}, 65 new int[] {R.ID.content_name, R.ID.content_date, R.ID.content_content}); 66 ListVIEw.setAdapter(simpleAdapter); 67 } else { 68 Log.i("smile", "查询成功,无数据返回"); 69 Toast.makeText(MainActivity.this, "讨论区还没内容哦!", Toast.LENGTH_LONG).show(); 70 } 71 } else { 72 Log.i("smile", "错误码:"+e.getErrorCode()+",错误描述:"+e.getMessage()); 73 Toast.makeText(MainActivity.this, "错误码:"+e.getErrorCode()+",错误描述:"+e.getMessage(), Toast.LENGTH_LONG).show(); 74 } 75 } 76 }); 77 78 send.setonClickListener(new VIEw.OnClickListener() { 79 @OverrIDe 80 public voID onClick(VIEw vIEw) { 81 String content = et_hf_content.getText().toString(); 82 if (content.equals("")) { 83 Toast.makeText(MainActivity.this, "发送内容为空!", Toast.LENGTH_LONG).show(); 84 } else { 85 CookContent cookContent = new CookContent(); 86 cookContent.setname("hemeiwolong"); 87 Date date = new Date(); 88 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); 89 cookContent.setDate(simpleDateFormat.format(date)); 90 cookContent.setContent(content); 91 cookContent.save(new SaveListener<String>() { 92 @OverrIDe 93 public voID done(String objectID,BmobException e) { 94 if(e==null){ 95 Toast.makeText(MainActivity.this, "添加数据成功,返回objectID为:"+objectID, Toast.LENGTH_LONG).show(); 96 onCreate(null); 97 }else{ 98 Toast.makeText(MainActivity.this, "创建数据失败:" + e.getMessage(), Toast.LENGTH_LONG).show(); 99 }100 }101 });102 }103 }104 });105 }106 }
总结
以上是内存溢出为你收集整理的android简易论坛的制作全部内容,希望文章能够帮你解决android简易论坛的制作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)