Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.58 KB | None | 0 0
  1. D:New folderDrawerWithSwipeTabsappsrcmainjavacomandroidbelievedrawerwithswipetabsnewsAdapter.java
  2. Error:(41, 65) error: no suitable method found for inflate(int,boolean)
  3. method LayoutInflater.inflate(int,ViewGroup) is not applicable
  4. (argument mismatch; boolean cannot be converted to ViewGroup)
  5. method LayoutInflater.inflate(XmlPullParser,ViewGroup) is not applicable
  6. (argument mismatch; int cannot be converted to XmlPullParser)
  7.  
  8. package com.androidbelieve.drawerwithswipetabs;
  9.  
  10. /**
  11. * Created by LENOVO on 21/2/2017.
  12. */
  13.  
  14. public class listnews {
  15.  
  16. public int id;
  17. public String imagedescription, image, imagepath, imagetitle;
  18.  
  19. public listnews(int id, String imagedescription, String image, String imagepath, String imagetitle) {
  20. this.id = id;
  21. this.imagedescription = imagedescription;
  22. this.image = image;
  23. this.imagepath = imagepath;
  24. this.imagetitle = imagetitle;
  25. }
  26.  
  27. public int getId() {
  28. return id;
  29. }
  30.  
  31. public void setId(int id) {
  32. this.id = id;
  33. }
  34.  
  35. public String getImagedescription() {
  36. return imagedescription;
  37. }
  38.  
  39. public void setImagedescription(String imagedescription) {
  40. this.imagedescription = imagedescription;
  41. }
  42.  
  43. public String getImage() {
  44. return image;
  45. }
  46.  
  47. public void setImage(String image) {
  48. this.image = image;
  49. }
  50.  
  51. public String getImagepath() {
  52. return imagepath;
  53. }
  54.  
  55. public void setImagepath(String imagepath) {
  56. this.imagepath = imagepath;
  57. }
  58.  
  59. public String getImagetitle() {
  60. return imagetitle;
  61. }
  62.  
  63. public void setImagetitle(String imagetitle) {
  64. this.imagetitle = imagetitle;
  65. }
  66. }
  67.  
  68. package com.androidbelieve.drawerwithswipetabs;
  69.  
  70. import android.content.Context;
  71. import android.provider.ContactsContract;
  72. import android.support.v4.app.Fragment;
  73. import android.support.v4.app.FragmentManager;
  74. import android.support.v4.app.FragmentPagerAdapter;
  75. import android.support.v7.widget.RecyclerView;
  76. import android.view.LayoutInflater;
  77. import android.view.View;
  78. import android.view.ViewGroup;
  79. import android.widget.ImageView;
  80. import android.widget.TextView;
  81.  
  82. import com.bumptech.glide.Glide;
  83.  
  84. import java.util.ArrayList;
  85. import java.util.List;
  86.  
  87. /**
  88. * Created by LENOVO on 20/2/2017.
  89. */
  90.  
  91.  
  92. public class newsAdapter extends RecyclerView.Adapter<newsAdapter.ViewHolder> {
  93.  
  94.  
  95.  
  96. private Context context;
  97. private List<listnews> my_data;
  98.  
  99. public newsAdapter(Context context, List<listnews> my_data)
  100. {
  101. this.context = context;
  102. this.my_data = my_data;
  103. }
  104.  
  105. @Override
  106. public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  107.  
  108. View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycle_news,false);
  109.  
  110. return new ViewHolder(itemView);
  111. }
  112.  
  113. @Override
  114. public void onBindViewHolder(ViewHolder holder, int position) {
  115.  
  116. holder.description.setText(my_data.get(position).getImagedescription());
  117. Glide.with(context).load(my_data.get(position).getImagepath()).into(holder.dataimage);
  118.  
  119. }
  120.  
  121. @Override
  122. public int getItemCount() {
  123. return 0;
  124. }
  125.  
  126. public static class ViewHolder extends RecyclerView.ViewHolder {
  127.  
  128. public TextView description;
  129. public TextView imagetitle;
  130. public ImageView dataimage;
  131.  
  132. public ViewHolder(View itemView) {
  133. super(itemView);
  134. description = (TextView) itemView.findViewById(R.id.textView3);
  135. imagetitle = (TextView) itemView.findViewById(R.id.textView4);
  136. dataimage = (ImageView) itemView.findViewById(R.id.imageView4);
  137.  
  138. }
  139. }
  140.  
  141. }
  142.  
  143. package com.androidbelieve.drawerwithswipetabs;
  144.  
  145. import android.app.LauncherActivity;
  146. import android.graphics.Movie;
  147. import android.os.AsyncTask;
  148. import android.os.Bundle;
  149. import android.support.annotation.Nullable;
  150. import android.support.v4.app.Fragment;
  151. import android.support.v7.widget.GridLayoutManager;
  152. import android.support.v7.widget.LinearLayoutCompat;
  153. import android.support.v7.widget.LinearLayoutManager;
  154. import android.support.v7.widget.RecyclerView;
  155. import android.view.LayoutInflater;
  156. import android.view.View;
  157. import android.view.ViewGroup;
  158.  
  159. import com.android.volley.RequestQueue;
  160. import com.android.volley.VolleyError;
  161. import com.android.volley.toolbox.StringRequest;
  162. import com.android.volley.toolbox.Volley;
  163.  
  164. import org.json.JSONArray;
  165. import org.json.JSONException;
  166. import org.json.JSONObject;
  167.  
  168. import java.io.IOException;
  169. import java.util.ArrayList;
  170. import java.util.List;
  171.  
  172. import okhttp3.OkHttpClient;
  173. import okhttp3.Request;
  174. import okhttp3.Response;
  175.  
  176. /**
  177. * Created by Ratan on 7/29/2015.
  178. */
  179.  
  180.  
  181. public class NewsFragment extends Fragment {
  182.  
  183. private RecyclerView mRecyclerView;
  184. private RecyclerView.Adapter mAdapter;
  185. private RecyclerView.LayoutManager mLayoutManager;
  186. private GridLayoutManager gridLayoutManager;
  187. private newsAdapter nAdapter;
  188. private List<listnews> data_list;
  189.  
  190.  
  191.  
  192.  
  193. @Override
  194. public void onCreate(Bundle savedInstanceState){
  195. super.onCreate(savedInstanceState);
  196.  
  197. }
  198.  
  199. @Override
  200. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
  201. {
  202. View view = inflater.inflate(R.layout.news_layout,container,false);
  203. mRecyclerView =(RecyclerView)view.findViewById(R.id.recyclerview);
  204. mRecyclerView.setHasFixedSize(true);
  205.  
  206. data_list = new ArrayList<>();
  207. load_data_from_server(0);
  208.  
  209. gridLayoutManager = new GridLayoutManager(this,2);
  210. mRecyclerView.setLayoutManager(gridLayoutManager);
  211.  
  212. nAdapter = new newsAdapter(this,data_list);
  213. mRecyclerView.setAdapter(nAdapter);
  214.  
  215. mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
  216. @Override
  217. public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
  218.  
  219. if(gridLayoutManager.findLastCompletelyVisibleItemPosition() == data_list.size()-1)
  220. {
  221. load_data_from_server(data_list.get(data_list.size()-1).getId());
  222. }
  223.  
  224. }
  225. });
  226.  
  227.  
  228.  
  229. return view;
  230.  
  231.  
  232.  
  233. private void load_data_from_server(final int id)
  234. {
  235. AsyncTask<Integer, Void, Void> task = new AsyncTask<Integer, Void, Void>() {
  236. @Override
  237. protected Void doInBackground(Integer... params) {
  238. OkHttpClient client = new OkHttpClient();
  239. Request request = new Request.Builder()
  240. .url("http://192.168.107.1/ibmcoe_la/selected.php?id="+id)
  241. .build();
  242.  
  243. try{
  244. Response response = client.newCall(request).execute();
  245.  
  246. JSONArray array = new JSONArray(response.body().string());
  247.  
  248. for(int i=0; i<array.length(); i++)
  249. {
  250. JSONObject object = array.getJSONObject(i);
  251.  
  252. listnews data = new listnews(object.getInt("news_id"),object.getString("path_image")
  253. ,object.getString("news_title"),object.getString("news_image"),object.getString("news_description"));
  254.  
  255. data_list.add(data);
  256. }
  257.  
  258.  
  259.  
  260. }catch (IOException e){
  261. e.printStackTrace();
  262. }catch (JSONException e){
  263. System.out.println("End of content");
  264. }
  265.  
  266. return null;
  267. }
  268.  
  269. protected void onPostExecute(Void avoid){
  270. nAdapter.notifyDataSetChanged();
  271. }
  272. };
  273.  
  274. task.execute(id);
  275. }
  276.  
  277. @Override
  278. public String toString()
  279. {
  280. return "NewsFragment";
  281. }
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288. }
  289.  
  290. <?xml version="1.0" encoding="utf-8"?>
  291. <RelativeLayout
  292. xmlns:android="http://schemas.android.com/apk/res/android"
  293. xmlns:app="http://schemas.android.com/apk/res-auto"
  294.  
  295.  
  296. android:orientation="vertical" android:layout_width="match_parent"
  297. android:layout_height="match_parent">
  298.  
  299. <TextView
  300. android:layout_width="wrap_content"
  301. android:layout_height="wrap_content"
  302. android:layout_marginTop="40dp"
  303. android:textSize="30sp"
  304. android:gravity="center"
  305. android:id="@+id/textView"
  306. android:layout_centerHorizontal="true"
  307. android:textColor="@android:color/holo_blue_dark"
  308. android:text="NewsnFragment"/>
  309.  
  310. <TextView
  311. android:layout_width="wrap_content"
  312. android:layout_height="wrap_content"
  313. android:autoLink="web"
  314. android:textSize="15sp"
  315. android:layout_marginTop="10dp"
  316. android:layout_centerHorizontal="true"
  317. android:text="androidbelieve.com"
  318. android:textColor="#000"
  319. android:layout_below="@+id/textView"
  320. android:textStyle="italic"/>
  321.  
  322. <android.support.v7.widget.RecyclerView
  323.  
  324. android:layout_width="match_parent"
  325. android:layout_height="match_parent"
  326. android:scrollbars="vertical"
  327. android:id="@+id/recyclerview"
  328. android:clickable="true"
  329. android:focusable="true"
  330. android:layout_alignParentTop="true"
  331. android:layout_alignParentLeft="true"
  332. android:layout_alignParentStart="true">
  333.  
  334. </android.support.v7.widget.RecyclerView>
  335.  
  336.  
  337. </RelativeLayout>
  338.  
  339. <android.support.v7.widget.CardView
  340. xmlns:android="https://schemas.android.com/apk/res/android"
  341. xmlns:android2="http://schemas.android.com/apk/res/android"
  342. xmlns:app="http://schemas.android.com/apk/res-auto"
  343. xmlns:card_view="https://schemas.android.com/apk/res-auto"
  344. xmlns:tools="http://schemas.android.com/tools"
  345. android:id="@+id/card_view"
  346. android:layout_width="match_parent"
  347.  
  348. android2:layout_marginTop="5dp"
  349. android2:layout_marginLeft="5dp"
  350. android2:layout_marginRight="5dp"
  351. android2:layout_gravity="center|top"
  352. card_view:cardPreventCornerOverlap="false"
  353. card_view:cardCornerRadius="20dp"
  354. android2:layout_width="match_parent"
  355. android2:layout_height="wrap_content">
  356.  
  357. <FrameLayout
  358. android2:layout_width="match_parent"
  359. android2:layout_height="400dp"
  360. app:cardElevation="0dp"
  361. android2:background="@drawable/cardviewstring">
  362.  
  363.  
  364.  
  365. <LinearLayout
  366. android2:orientation="vertical"
  367. android2:layout_width="380dp"
  368. android2:layout_height="match_parent"
  369.  
  370.  
  371. android2:weightSum="1"
  372. android2:layout_marginRight="20dp">
  373.  
  374. <LinearLayout
  375. android2:orientation="vertical"
  376. android2:layout_width="match_parent"
  377. android2:layout_weight="1"
  378. android2:layout_height="250dp">
  379.  
  380. <ImageView
  381. android2:layout_width="match_parent"
  382. android2:layout_height="match_parent"
  383. app:srcCompat="@mipmap/ic_launcher"
  384. android2:id="@+id/imageView4" />
  385.  
  386. </LinearLayout>
  387.  
  388. <LinearLayout
  389. android2:orientation="vertical"
  390. android2:layout_width="match_parent"
  391. android2:layout_height="wrap_content"
  392. android2:paddingTop="25dp">
  393.  
  394. <ScrollView
  395. android2:layout_width="match_parent"
  396. android2:layout_height="84dp"
  397. android2:background="@drawable/screen_background_dark_transparent"
  398. android2:layout_marginLeft="3dp">
  399.  
  400. <LinearLayout
  401. android2:layout_width="match_parent"
  402. android2:layout_height="wrap_content"
  403. android2:orientation="vertical" >
  404.  
  405. <TextView
  406. android2:text="TextView"
  407. android2:layout_width="match_parent"
  408. android2:layout_height="wrap_content"
  409. android2:id="@+id/textView4" />
  410.  
  411. <TextView
  412. android2:text="TextView"
  413. android2:layout_width="match_parent"
  414. android2:layout_height="35dp"
  415. android2:id="@+id/textView3" />
  416. </LinearLayout>
  417. </ScrollView>
  418.  
  419. </LinearLayout>
  420.  
  421. <LinearLayout
  422. android2:orientation="vertical"
  423. android2:layout_marginTop="10dp"
  424. android2:layout_width="match_parent"
  425. android2:layout_height="42dp"
  426. android:layout_alignParentBottom="true">
  427.  
  428. <LinearLayout
  429. android2:orientation="horizontal"
  430. android2:layout_width="match_parent"
  431. android2:layout_height="match_parent">
  432.  
  433. <ImageView
  434. android2:layout_width="wrap_content"
  435. android2:layout_height="wrap_content"
  436. app:srcCompat="@drawable/ic_share"
  437. android2:id="@+id/imageView3"
  438. android2:layout_weight="1" />
  439.  
  440. <ImageView
  441. android2:layout_width="wrap_content"
  442. android2:layout_height="wrap_content"
  443. app:srcCompat="@drawable/ic_like"
  444. android2:id="@+id/imageView2"
  445. android2:layout_weight="1" />
  446. </LinearLayout>
  447. </LinearLayout>
  448. </LinearLayout>
  449.  
  450. </FrameLayout>
  451.  
  452. </android.support.v7.widget.CardView>
  453.  
  454. <?php
  455.  
  456. $host = "localhost";
  457. $user = "root";
  458. $pass = "";
  459. $db = "ibmcoe1.4";
  460.  
  461. $con = mysqli_connect($host,$user,$pass,$db);
  462.  
  463. $query = "SELECT * FROM news order by news_timepost DESC";
  464. $result = mysqli_query($con,$query);
  465. $response = array();
  466.  
  467. while ($row = mysqli_fetch_array($result))
  468. {
  469. array_push($response,array('news_id'=>$row[0],'path_image'=>$row[1],'news_title'=>$row[2],'news_description'=>$row[3],'news_timepost'=>$row[5]));
  470. }
  471. mysqli_close($con);
  472. echo json_encode(array('server_response'=>$response));
  473. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement